#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
int t,n,m,v;
struct node{
	int x,y;
}a[N];
bool cmp(node x,node y){
	return x.x<y.x;
}
int ksm(int a,int b){
	int sum=1;
	while(b){
		if(b&1)sum=1ll*sum*a%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return sum;
}
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+1+m,cmp);
		bool flag=0;
		for(int i=1;i<m;i++){
			if(a[i].x==a[i+1].x&&a[i].y!=a[i+1].y)flag=1;
		}
		if(flag){
			printf("0\n");
			continue;
		}
		int ans=1,now=n-1;
		for(int i=2;i<=m;i++){
			int len=a[i].x-a[i-1].x;
			if(len){
				now-=len;
				ans=ans*(ksm(1ll*v*v%mod,len)-1ll*ksm(v,len-1)*(v-1)%mod+mod)%mod;
				ans%=mod;
			}
		}
		ans=ans*ksm(v*v%mod,now)%mod;
		printf("%lld\n",ans);
	}
	return 0;
}
/*
10 11 2
10 2
7 2
2 2
3 2
4 2
*/
