#include<bits/stdc++.h>
#define int long long
#define MAXN 200005
#define mod 1000000007
using namespace std;
int T,n,m,V,c[MAXN],d[MAXN],ans;
int fpow(int a,int b){
	int tans=1;
	while(b){
		if(b&1)tans=tans*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return tans;
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld%lld",&n,&m,&V);
		bool r=1;
		for(int i=1;i<=m;i++){
			scanf("%lld%lld",&c[i],&d[i]);
		}
		map<int,int>ma;
		for(int i=1;i<=m;i++){
			if(!ma.count(c[i])){
				ma[c[i]]=d[i];
			}else if(ma[c[i]]!=d[i]){
				r=0;
			}
		}
		sort(c+1,c+m+1);
		ans=fpow(V*V%mod,c[1]-1);
		for(int i=2;i<=m;i++){
			if(c[i]==c[i-1])continue;
			if(c[i]!=c[i-1]+1){
				ans=ans*((fpow(V*V%mod,c[i]-c[i-1])+mod-fpow(V,c[i]-c[i-1]-1)*(V-1)%mod)%mod)%mod;
			}else{
				ans=ans*((1+(V-1)*V)%mod)%mod;
			}
		}
		ans=ans*fpow(V*V%mod,n-c[m])%mod;
		ans*=r;
		printf("%lld\n",ans);
	}
	return 0;
}

