#include <bits/stdc++.h>
using namespace std;
#define int long long 
const int N=1e6+5;
const int mod=1e9+7;
int T;
int n;
int c[N],d[N];
int qpow(int a,int b){
	int ans=1; 
	while(b>0){
		if(b%2==1)ans=(ans*a)%mod;
		b/=2,a=(a*a)%mod;
	}
	return ans;
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.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){
			int ans=0;
			ans=qpow(v*v,c[i]-1)%mod;
			ans*=(v*v-v+1);
			nas=ans*qpow(v*v,n-c[i])%mod;
			cout<<ans<<"\n";
		}
		if(n==m){
			int tmp=(v*v-v+1)%mod;
			cout<<qpow(tmp,n-1)%mod<<"\n";
		}
		
	}
	return 0;
}
