#include<bits/stdc++.h>
using namespace std;
const int M=1e5+3;
const long long p=1e9+7;
int T,n,m,m1;
long long v,cnt,ans;
struct nd{
	long long x,y;
}a[M],b[M];
bool cmp(nd x,nd y){
	return x.x<y.x;
}
void mul(long long &x,long long y){
	(x*=y)%=p;return;
}
void add(long long &x,long long y){
	(x+=y)%=p;return;
}
long long ksm(long long x,long long y){
	long long s=1;
	while(y){
		if(y&1) mul(s,x);
		mul(x,x),y>>=1; 
	}
	return s;
}
void solve(){
	m1=0;
	for(int i=1;i<=m;i++){
		if(a[i].x!=a[i-1].x) b[++m1]=a[i];
		else if(a[i].y!=a[i-1].y){
			printf("0\n");return;
		}
	}
	ans=ksm(v,2*((b[1].x-1)+(n-b[m1].x)));
	for(int i=2;i<=m1;i++){
		long long j=b[i].x-b[i-1].x,cnt=0;
		cnt=ksm(v,j-1);
		add(cnt,(v-1)*(ksm(v,j)*(ksm(v,j)-1)%p*ksm(v-1,p-2)%p)%p);
		mul(ans,cnt);
	}
	printf("%lld\n",ans);
	return;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%lld",&n,&m,&v);
		for(int i=1;i<=m;i++){
			scanf("%lld%lld",&a[i].x,&a[i].y);
		}
		sort(a+1,a+1+m,cmp);
		solve();
	}
	return 0;
}
