#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=1e5+10;
int n,m,v,ans,cnt,pos[maxn];
pair<int,int> p[maxn];
int ksm(int a,int b){
	int res=1;
	while(b){
		if(b&1) res=1ll*res*a%mod;
		b>>=1;
		a=1ll*a*a%mod;
	}
	return res;
}
int mn(int a,int b){
	if(a<b) return a-b+mod;
	return a-b;
}
int read(){
	int x=0;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return x;
}
void solve(){
	ans=1;
	n=read(),m=read(),v=read();
	for(int i=1;i<=m;i++) p[i].first=read(),p[i].second=read();
	sort(p+1,p+m+1);
	int tmp=1ll*v*v%mod;
	cnt=1;
	pos[1]=p[1].first;
	for(int i=2;i<=m;i++){
		if(p[i].first==p[i-1].first&&p[i].second!=p[i-1].second){
			puts("0");
			return;
		}
		if(p[i].first!=p[i-1].first) pos[++cnt]=p[i].first;
	}
	if(cnt<=1){
		printf("%d\n",ksm(tmp,n-1));
		return;
	}
	ans=1ll*ksm(tmp,pos[1]-1)*ksm(tmp,n-pos[cnt])%mod;
	for(int i=1;i<cnt;i++){
		ans=1ll*ans*mn(ksm(tmp,pos[i+1]-pos[i]),1ll*ksm(v,pos[i+1]-pos[i]-1)*(v-1)%mod)%mod;
	}
	printf("%d\n",ans);
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int t=read();
	while(t--) solve();
}