#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MOD=1e9+7;
const int NUM=1e5+6;
pair<int,int> a[NUM];
void solve(){
	int n,m,v;
	cin>>n>>m>>v;
	bool flag=0;
	for(int i=1;i<=m;i++){
		int x,y; cin>>x>>y;
		a[i]={x,y};
	}
	sort(a+1,a+m+1);
	int ans=1;
	auto ksm=[&](auto self,int x,int p)->int{
		if(p==0) return 1;
		if(p==1) return x;
		int res=self(self,x,p>>1);
		if(p&1) return (((res*res)%MOD*x)%MOD);
		else return ((res*res)%MOD);
	};
	for(int i=1;i<m;i++){
		if(a[i].first==a[i+1].first){
			if(a[i].second!=a[i+1].second){
				flag=1; break;
			}
			else continue;
		}
		ans=(ans*(((v-1)*v+1)%MOD))%MOD;
		ans=(ans*ksm(ksm,(v*v)%MOD,max(0LL,a[i+1].first-a[i].first-2)))%MOD;
	}
	if(flag){
		cout<<0<<"\n";
		return;
	}
	ans=(ans*ksm(ksm,(v*v)%MOD,n-a[m].first+a[1].first-1))%MOD;
	cout<<(flag?0LL:ans)<<"\n";
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int t; cin>>t;
	while(t--) solve();
	return 0;
}
