#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7,N=1e5+10;
int t,n,m,v,ans;
struct node{
	int x,y;
}a[N];
bool cmp(node x,node y){
	return x.x<y.x;
}
int ksm(int qwq,int qvq){
	int s=1,pp=qwq;
	while(qvq){
		pp%=mod;
		if(qvq&1){
			s*=pp;
			s%=mod;
		}
		pp*=pp;
		qvq>>=1;
	}
	return s;
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&t);
	while(t--){
		scanf("%lld %lld %lld",&n,&m,&v);
		for(int i=1;i<=m;i++){
			scanf("%lld %lld",&a[i].x,&a[i].y);
		}
		sort(a+1,a+m+1,cmp);
		ans=1;
		ans*=ksm(v,(a[1].x-1)*2);
		ans%=mod;
		ans*=ksm(v,(n-a[m].x)*2);
		ans%=mod;
		for(int i=2;i<=m;i++){
			if(a[i].x==a[i-1].x&&a[i-1].y!=a[i].y){
				ans=0;
				break;
			}
			if(a[i].x==a[i-1].x)continue;
			int s=(ksm(v,(a[i].x-a[i-1].x)*2)+mod-(v-1)*ksm(v,a[i].x-a[i-1].x-1)%mod)%mod;
			ans*=s;
			ans%=mod;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
/*256
0
4096
129600
4194304
503279958
748525720
892897109
174281099
418965370

*/
