#include<bits/stdc++.h>
#define ci const int
#define ll long long
using namespace std;
int read(){
	char ch=getchar();
	int res=0;
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
	return res;
}
ci mod=1e9+7,N=1e5+5;
ll qk(ll x,int y=mod-2){
	ll ans=1;
	while(y){
		if(y&1)ans=ans*x%mod;
		x=x*x%mod,y>>=1;
	}
	return ans;
}
int n,m,v,x[N],len,p;
void Init(){
	len=0,p=1,n=m=v=0;
}
struct node{
	int c,d;
	inline bool operator < (const node &t)const{
		return c<t.c;
	}
}nd[N];
int calc(ci L){
	int all=qk(v,L+L);
	int pr=qk(v,L-1)*(v-1)%mod;
	return (ll)(all-pr+mod)*qk(all)%mod;
}
void Work(){
	n=read(),m=read(),v=read();
	for(int i=1;i<=m;++i)nd[i].c=read(),nd[i].d=read();
	sort(nd+1,nd+m+1);
	for(int i=2;i<=m;++i)
		if(nd[i].c==nd[i-1].c&&nd[i].d!=nd[i-1].d){
			puts("0");
			return;
		}
	for(int i=1;i<=m;++i)
		if(i==1||nd[i].c!=nd[i-1].c)
			x[++len]=nd[i].c;
	p=1;
	for(int i=1;i<len;++i)p=(ll)p*calc(x[i+1]-x[i])%mod;
	p=p*qk(v,n-1+n-1)%mod;
	printf("%d\n",p);
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	for(int T=read();T;--T)Work(),Init();
	return 0;
}