#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define int long long
int zu,n,m,v;
const int mod=1e9+7;
int c[N],l[N],f[N];
int ksm(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=ans*x%mod;
		x=x*x%mod,y>>=1;
	}
	return ans;
}
struct A{
	int c,d;
}d[N];
bool cmp(A a,A b){
	return a.c<b.c;
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&zu);
	while(zu--){
		scanf("%lld%lld%lld",&n,&m,&v);
		int fl=0;
		for(int i=1;i<=m;i++){
			scanf("%lld%lld",&d[i].c,&d[i].d);
		}
		sort(d+1,d+1+m,cmp);
		int tot=0;
		for(int i=1;i<=m;i++){
			if(d[i].c==d[i-1].c){
				if(d[i].d!=d[i-1].d){
					printf("0\n");
					fl=1;
					break;
				}
				continue;
			}
			c[++tot]=d[i].c;
		}
		m=tot;
		if(fl) continue;
		c[0]=1;
		for(int i=1;i<=m;i++) l[i]=c[i]-c[i-1]-1;
		f[1]=ksm(v*v%mod,c[1]-1);
//		printf("%lld\n",m);
		for(int i=2;i<=m;i++){
			int val=ksm(v,l[i]);
			f[i]=f[i-1]*(val*val%mod*v%mod-val*(v-1)%mod+mod)%mod;
			f[i]+=f[i-1]*(val*val%mod*(v-1)%mod*v%mod)%mod;
			f[i]%=mod;
		}
		if(c[m]==n){
			printf("%lld\n",f[m]%mod);
			continue;
		}
		int val=ksm(v,n-c[m]-1);
		printf("%lld\n",(f[m]*(v-1)%mod+f[m])*val%mod*val%mod*v%mod);
	}
	return 0;
}

