#include<bits/stdc++.h>
using namespace std;

#define LL long long

void read(LL &x){
	scanf("%lld",&x);
}

void write(LL x,LL op=1){
	if(!op) printf("%lld ",x);
	else printf("%lld\n",x);
}

LL qsm(LL a,LL b,LL mod){
	LL ans=1,sum=a;
	while(b){
		if(b&1) ans=ans*sum%mod;
		sum=sum*sum%mod;
		b>>=1;
	}
	return ans;
}

const LL N=1e5+10,mod=1e9+7;

LL n,m,v;

LL c[N],d[N];

map<LL,LL> mp;

void solve(){
	read(n),read(m),read(v);
	for(LL i=1;i<=m;i++) read(c[i]),read(d[i]);
	mp.clear();
	for(LL i=1;i<=m;i++){
		if(mp[c[i]]){
			if(d[i]!=mp[c[i]]){
				write(0);
				return ;
			}
		}
		else{
			mp[c[i]]=d[i];
		}
	}
	sort(c+1,c+m+1);
	LL ans=1;
	ans=ans*qsm(v*v%mod,c[1]-1+n-c[m],mod)%mod;
	for(LL i=2;i<=m;i++){
		if(c[i]==c[i-1]) continue;
		ans=ans*(qsm(v*v%mod,c[i]-c[i-1],mod)-qsm(v,c[i]-c[i-1]-1,mod)*(v-1)%mod+mod)%mod;
//		write((qsm(v*v%mod,c[i]-c[i-1],mod)-qsm(v,c[i]-c[i-1]-1,mod)*(v-1)%mod+mod)%mod);
	}
	write(ans);
}

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	LL T=1;
	read(T);
	while(T--){
		solve();
	}
	return 0;
}

