#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll N=1000005,mod=1000000007;
ll tn,nn,xn,vn,dp[N][2],jl[N];
struct XZ{
	ll w,v;
}xz[N];
bool cmp(XZ n1,XZ n2){
	return n1.w<n2.w;
}
ll cha(ll l,ll r){
	return ((jl[r]-jl[l-1])%mod+mod)%mod;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&tn);
	for(;tn>0;tn--){
		memset(dp,0,sizeof(dp));
		scanf("%lld%lld%lld",&nn,&xn,&vn);
		jl[0]=1;
		for(ll i=1;i<N;i++){
			jl[i]=jl[i-1]*vn%mod;
		}
		for(ll i=1;i<N;i++){
			jl[i]=(jl[i]+jl[i-1])%mod;
		}
		for(ll i=1;i<=xn;i++){
			scanf("%lld%lld",&xz[i].w,&xz[i].v);
		}
		sort(xz+1,xz+xn+1,cmp);
//		for(ll i=1;i<=xn;i++){
//			printf("[%lld %lld] ",xz[i].w,xz[i].v);
//		}
//		printf("\n");
		ll ls=0;
		for(ll i=1;i<xn;i++){
			if(xz[i].w==xz[i+1].w && xz[i].v!=xz[i+1].v){
				ls=1;
				break;
			}
		}
		if(ls==1){
			printf("0\n");
			continue;
		}
		if(xz[1].w==1){
			dp[1][0]=0;
			dp[1][1]=1;
		}else{
			dp[1][0]=1;
			dp[1][1]=0;
		}
		xz[xn+1].w=nn+1;
//		printf("[%lld %lld] ",dp[1][0],dp[1][1]);
		int cnt=1;
		for(ll i=1,z=1;i<nn;i++){
			while(z<=xn && (xz[z].w<=i || xz[z].w==xz[z+1].w)){
				z++;
			}
//			printf("%lld\n",xz[z].w);
			if(xz[z].w!=i+1){
				ll ls=xz[z].w-i-1,x=0;
				if(ls*2>=N){
					ls=(N-1)/2;
					x=1;
				}
//				printf("[%lld]\n",cha(ls,ls));
				dp[cnt+1][0]=(cha(2*ls,2*ls)*dp[cnt][0]%mod+cha(ls-1,ls*2-2)*vn%mod*(vn-1)%mod*dp[cnt][1])%mod;
				dp[cnt+1][1]=cha(ls,ls)*dp[cnt][1]%mod;
				if(x==0){
					i=xz[z].w-2;
				}else{
					i+=ls-1;
				}
			}else{
				dp[cnt+1][0]=0;
				dp[cnt+1][1]=(dp[cnt][0]*vn%mod*vn%mod+dp[cnt][1]*((vn-1)*vn%mod+1)%mod)%mod;
			}
			cnt++;
		}
//		printf("\n");
		printf("%lld\n",((dp[cnt][0]+dp[cnt][1])%mod+mod)%mod);
	}
	return 0;
}
