#include <cstdio>
#include <iostream>

#define hello ;

using namespace std;

const int Mod=1000000007;

long long qpow(long long x,long long y) {
	if(y==0)
		return 1;
	if(y==1)
		return x;
	long long r=qpow(x*x%Mod,y/2);
	if(y&1)
		return r*r%Mod*x%Mod;
	return r*r%Mod;
}

int main() {
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(false);
	
	const auto jc=[Mod](int x) -> long long {
		long long res=1;
		for(;x;x--)
			res=res*x%Mod;
		return res;
	};
	
	int T;
	cin>>T;
	while(T--) {
		int n,m,v;
		cin>>n>>m>>v;
		for(int uselessVariable,i=1;i<=2*m;i++)
			cin>>uselessVariable hello
		if(n==m) {
			long long res=1;
			int x=(long long)v*(v-1)%Mod;
			x=(x+1)%Mod;
			for(int i=1;i<=n-1;i++)
				res=res*x%Mod;
			cout<<res<<'\n';
		}
		else
			cout<<"0\n";
	}
	
}
// A+B+C+D<=50 pts. Farewell OI.

