#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10,mod=1e9+7;
int n,m,T,V,dp[N][2],ans;
bool flag;
struct node{
	int d,c;
}p[N];
bool cmp(node a,node b){
	return a.c<b.c;
}
int power(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=ans*x%mod;
		x=x*x%mod;
		y/=2; 
	}
	return ans;
}
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",&p[i].c,&p[i].d);
		sort(p+1,p+1+m,cmp);
		flag=0;
		for(int i=1;i<=m;i++) if((p[i].c==p[i-1].c&&p[i].d!=p[i-1].d)||(p[i].d>V||p[i].d<1)) flag=1;
		if(flag){
			printf("0\n");
			continue;
		}
		if(V==1){
			printf("1\n");
			continue;
		}
		if(m<=1){
			ans=power(V*V%mod,n-1);
			printf("%lld\n",ans);
			continue;
		}
		ans=1;
		for(int i=m;i>1;i--){
			if(p[i].c==p[i-1].c) continue;
			else ans=ans*(power(V*V%mod,p[i].c-p[i-1].c)-(power(V,p[i].c-p[i-1].c-1)%mod*(V-1))%mod)%mod;
		}
		if(p[m].c!=n) ans=ans*power(V*V%mod,n-p[m].c)%mod;
		if(p[1].c!=1) ans=ans*power(V*V%mod,p[1].c-1)%mod;
		printf("%lld\n",(ans+mod)%mod);
	}
	return 0;
}
/*
1
10 5 2
2 2
3 2
4 2
7 2
10 2


*/
