#include<bits/stdc++.h>
#define int long long
const int mod=1e9+7,MAXN=1e5+5;
inline int qpow(int a,int b){
	int ret(1);
	while(b>0){
		if(b&1) ret=ret*a%mod;
		a=a*a%mod,b>>=1;
	}
	return ret;
}
int T,n,m,V;
struct node{
	int c,d;
}a[MAXN];
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld%lld",&n,&m,&V);
		for(int i=1;i<=m;i++) scanf("%lld%lld",&a[i].c,&a[i].d);
		std::sort(a+1,a+m+1,[](node x,node y){return x.c<y.c;});
		int ans(1);
		ans=ans*qpow(V*V%mod,a[1].c-1);
		for(int i=1;i<m;i++){
			if(a[i].c==a[i+1].c&&a[i].d!=a[i+1].d){
				ans=0;
				break;
			}
			if(a[i].c==a[i+1].c) continue;
			ans=ans*qpow(V*V%mod,a[i+1].c-a[i].c-1)%mod;
			if(a[i].c==a[i+1].c-1) ans=ans*((V-1ll)*V%mod+1ll)%mod;
			else ans=ans*(V*V%mod)%mod;
		}
		ans=ans*qpow(V*V%mod,n-a[m].c)%mod;
		printf("%lld\n",ans);
	}
}
