#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 5,mod = 1e9 + 7;
int T,n,m,v,c[N],d[N];
int qp(int x,int k){
	int res = 1;
	while(k){
		if(k & 1) res = res * x % mod;
		x = x * x % mod;
		k >>= 1;
	}
	return res;
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin >> T;
	while(T--){
		cin >> n >> m >> v;
		for(int i = 1; i <= m; i++) cin >> c[i] >> d[i];
		if(m == 1) cout << qp(v,2 * n - 2) << '\n';
		else cout << 0 << '\n';
	}
	return 0;
}
