#include<iostream>
#include<cstdio>
#include<cstring> 
#include<algorithm>
using namespace std;

const long long mod=1e9+7;
long long f[100005];
long long n,m,v;
struct nd{
	long long c,d;
}p[100005];

long long qpow(long long a,long long b){
	long long ans=1,base=a;
	while(b){
		if(b&1){
			ans*=base;
			ans%=mod;
		}
		base*=base;
		base%=mod;
		b/=2;
	}
	return ans;
}

bool cmp(nd t1,nd t2){
	return t1.c<t2.c;
}

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	long long T;scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld%lld",&n,&m,&v);
		for(long long i=1;i<=m;i++){
			scanf("%lld%lld",&p[i].c,&p[i].d);
			f[i]=0;
		}	
		sort(p+1,p+m+1,cmp);
		bool fl=1;
		for(int i=2;i<=m;i++){
			if(p[i].c==p[i-1].c&&p[i].d!=p[i-1].d){
				fl=0;
				break;
			}
		}
		if(!fl){
			puts("0");
			continue;
		}
		f[0]=1;
		for(long long i=1;i<=m;i++){
			if(p[i].c==1){
				f[1]=1;
				continue;
			}
			if(i==1){
				f[1]=qpow(v,2*p[1].c-2);
				continue;
			}
			if(p[i-1].c==p[i].c){
				f[i]=f[i-1];
				continue;
			}
			long long nw=p[i].c;
			long long len=p[i].c-p[i-1].c;
			f[i]=f[i-1]*((qpow(v,2*len)-qpow(v,len-1)*(v-1)%mod)%mod)%mod;
		}
		long long ans=f[m];
		long long len=n-p[m].c;
		ans=(ans*qpow(v,2*len))%mod;
		ans=(ans%mod+mod)%mod;
		printf("%lld\n",ans);
	} 
	return 0;
}
