#include<bits/stdc++.h>
#define Ri register int 
#define LL long long 
using namespace std;
const int N=2e5+15;
const LL mo=1e9+7;
LL ksm(LL x,LL y){
	LL res=1;
	while(y>0){
		if(y&1) res=res*x%mo;
		x=x*x%mo;
		y>>=1;
	}
	return res;
}
int m;
LL n,V;
struct abc{
	int x,y;
}A[N];
int cmp(abc aa,abc bb){
	return aa.x<bb.x;
}
void Sol(){
	scanf("%lld %d %lld",&n,&m,&V);
	for(Ri i=1; i<=m; ++i){
		scanf("%d %d",&A[i].x,&A[i].y);
	}
	sort(A+1,A+1+m,cmp);
	LL ans=ksm(V,2*(n-A[m].x+A[1].x-1));
	for(Ri i=2; i<=m; ++i){
		if(A[i].x==A[i-1].x && A[i].y!=A[i-1].y) ans=0;
		int len=A[i].x-A[i-1].x;
		if(len>0){
			ans=ans*(ksm(V,2*len)-ksm(V,len-1)*(V-1)%mo+mo)%mo;
		}
	}
	printf("%lld\n",ans);
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--) Sol();
}
