#include<bits/stdc++.h>
#define int long long//
using namespace std;
const int mod=1e9+7;
int T,n,m,v,a[100010];
map<int,int>mp;
int ksm(int a,int b){
	int res=1;
	while(b){
		if(b&1)res=res*a%mod;
		a=a*a%mod,b>>=1;
	}
	return res;
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		mp.clear();
		scanf("%lld%lld%lld",&n,&m,&v);
		int fl=0;
		for(int i=1,x;i<=m;i++){
			scanf("%lld%lld",&a[i],&x);
			if(mp[a[i]]&&mp[a[i]]!=x)fl=1;
			mp[a[i]]=x;
		}
		if(fl){
			printf("0\n");
			continue;
		}
		sort(a+1,a+m+1);//
		m=unique(a+1,a+m+1)-a-1;
		int ans=ksm(v,2*(a[1]-1))*ksm(v,2*(n-a[m]))%mod;
		for(int i=2;i<=m;i++)
			ans=ans*(ksm(v,2*(a[i]-a[i-1]))-ksm(v,a[i]-a[i-1]-1)*(v-1)%mod+mod)%mod;
		printf("%lld\n",ans);
	}
	return 0;
}
