#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int M=1e9+7;
int t,n,m,v,c[100010],d[100010];
int qsm(int x,int y){
	int re=1,ba=x;
	while(y){
		if(y&1){
			re=((re%M)*(ba%M))%M;
		}
		ba=((ba%M)*(ba%M))%M;
		y>>=1;
	}
	return re%M;
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>t;
	while(t--){
		int sum=0,ans=1;
		bool p=0;
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++){
			cin>>c[i]>>d[i];
		}
		stable_sort(c+1,c+1+m);
		for(int i=2;i<=m;i++){
			if(c[i]==c[i-1]+1)sum++;
			if(c[i]==c[i-1]){p=1;break;}
		}
		if(p==1){cout<<0<<endl;continue;}
		int g=(n-2*sum)%M;
		ans=qsm(v%M,abs(g));
		int ha=(((v-1)%M)*(v%M))%M;ha++;
		ans=(ans%M)*(qsm(ha,sum));
		cout<<ans<<endl;
	}
	return 0;
}
