#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const ll mod=1e9+7;
struct dian{
	ll w,z;
}yd[200005];
ll t,n,m,v,ans;
bool cmp(dian a,dian b){
	return a.w<b.w;
}
ll fm(ll x,ll m){
	ll dc=x,s=1;
	while(m){
		if(m&1)s=s*dc%mod;
		dc=dc*dc%mod;
		m>>=1;
	}
	return s;
}
int main(){
//	freopne("assign.in","r",stdin);
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&t);
	while(t--){
		scanf("%lld%lld%lld",&n,&m,&v);
		for(ll i=1;i<=m;i++){
			scanf("%lld%lld",&yd[i].w,&yd[i].z);
		}
		yd[m+1].w=yd[m+1].z=0;
		sort(yd+1,yd+1+m,cmp);
		ans=fm(v,2*yd[1].w-2);
		bool hhh=0;
		for(ll i=1;i<m;i++){
			if(yd[i+1].w==yd[i].w){
				if(yd[i+1].z==yd[i].z)continue;
				hhh=1;
				break;
			}
			ans=ans*(fm(v,(yd[i+1].w-yd[i].w)<<1)-(fm(v,yd[i+1].w-yd[i].w-1)*(v-1)%mod)+mod)%mod%mod;
		}
		if(hhh){
			printf("0\n");
			continue;
		}
		ans=ans*fm(v,(n-yd[m].w)<<1)%mod;
		ans=(ans+mod)%mod;
		printf("%lld\n",ans);
	}
	return 0;
}
