#include<bits/stdc++.h>
#define int long long
using namespace std;
const int M=1e5,MOD=1e9+7;
int T;
int n,m,v;
int q[M+10],len[M+10];
int dp[M+10] [2],pre0[M+10],pre1[M+10];
struct Node{
	int c,d;
}Num[M+10];
bool cmp(Node x,Node y){
	return x.c<y.c||x.c==y.c&&x.d<y.d;
}
int Pow(int x,int y){
	int res=1;
	for(;y;y>>=1){
		if(y&1)
			res=(res*x)%MOD;
		x=(x*x)%MOD; 
	}
	return res;
}
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",&Num[i].c,&Num[i].d);
		sort(Num+1,Num+1+m,cmp);
		int tot=0;
		bool flag=true;
		for(int i=1;i<=m;i++){
			if(i!=m&&Num[i].c==Num[i+1].c&&Num[i].d!=Num[i+1].d){
				printf("0\n");
				flag=false;
				break;
			}
			if(i==m||!(Num[i].c==Num[i+1].c&&Num[i].d==Num[i+1].d))
				q[++tot]=Num[i].c;
		}
		if(!flag)
			continue;
		for(int i=1;i<=tot-1;i++)
			len[i]=q[i+1]-q[i]+1;
		int ans=Pow(v*v%MOD,n-1);
		pre0[0]=Pow(v*v%MOD,n-1);
		pre1[0]=0;
		for(int i=1;i<=tot-1;i++){
			dp[i] [0]=pre1[i-1]*(v-1)%MOD*Pow(Pow(v,len[i]),MOD-2)%MOD;
			dp[i] [1]=pre0[i-1]*(v-1)%MOD*Pow(Pow(v,len[i]),MOD-2)%MOD;
			pre0[i]=(pre0[i-1]+dp[i] [0])%MOD;
			pre1[i]=(pre1[i-1]+dp[i] [1])%MOD;
			ans=(ans-dp[i] [1]+MOD)%MOD;
			ans=(ans+dp[i] [0])%MOD;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
