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

typedef long long ll;
const int mod=1e9+7;
int T;
int n,m,v;
struct node{
	int c,d;
	
	bool operator <(const node &b) const{
		return c<b.c;
	}
}ns[100010];
ll dp[100010][2];

ll qpow(ll a,int b){
	if(b<0) return 0ll;
	ll c=1;
	while(b){
		if(b&1) c=c*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return c;
}

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d",&n,&m,&v);
		ll ans=qpow((1ll*v*v)%mod,n-1);
		for(int i=1;i<=m;i++) scanf("%d%d",&ns[i].c,&ns[i].d);
		sort(ns+1,ns+1+m);
		dp[0][0]=1;
		dp[0][1]=0;
		for(int i=1;i<m;i++){
			if(ns[i].c==ns[i+1].c){
				if(ns[i].d!=ns[i+1].d){
					ans=0;
					break;
				}
			}
			if(ns[i].c==ns[i+1].c){
				dp[i][0]=dp[i-1][0];
				dp[i][1]=dp[i-1][1];
				continue;
			}
			int len=ns[i+1].c-ns[i].c-1;
			ll v1=qpow(v,len)*(v-1)%mod,v2=qpow((1ll*v*v)%mod,len+1);
			dp[i][0]=dp[i-1][0]*((v2-v1+mod)%mod)%mod;
			dp[i][1]=((dp[i-1][1]*v2%mod)+(dp[i-1][0]*v1%mod))%mod;
		}
		if(ans==0) printf("0\n");
		else{
			int len=ns[1].c-1+n-ns[m].c;
			dp[m-1][1]=dp[m-1][1]*qpow((1ll*v*v)%mod,len)%mod;
			ans=(ans-dp[m-1][1]+mod)%mod;
			printf("%lld\n",ans);
		}
	}
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
}
