#include<iostream>
#include<cstdio>
using namespace std;

typedef long long ll;
const int N=100010;
const ll mod=1e9+7;
ll c[N],d[N];

ll qpow(ll p,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=res*p%mod;
		p=p*p%mod;
		b>>=1;
	}
	return res;
}

int main()
{
//	freopen("assign.in","r",stdin);freopen("assign.out","w",stdout);
	int t;
	cin>>t;
	while(t--)
	{
		ll n,m,v;
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++)cin>>c[i]>>d[i];
		cout<<qpow(v*v%mod,n-1)<<'\n';
	}
	return 0;
}
