#include<bits/stdc++.h>
using namespace std;
const int M=1e5+10;
const int mod=1e9+7;
#define ll long long
int t;
ll n,m,v;
ll c[M],d[M];
ll ksm(ll b){
	ll a=v;
	ll ans=1;
	while(b){
		if(b&1){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans%mod;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>t;
	while(t--){
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++){
			cin>>c[i]>>d[i];
		}
		sort(c+1,c+m+1);
		bool flag=0;
		ll ans=1;
		if(c[1]!=1ll){
			ll ik=ksm(c[1]-1);
			ik=(ik*ik)%mod;
			ans=(ans*ik)%mod;
		}
		if(c[m]!=n){
			ll ik=ksm(n-c[m]);
			ik=(ik*ik)%mod;
			ans=(ans*ik)%mod;
		}
		for(int i=1;i<m;i++){
			if(c[i]==c[i+1]&&d[i]!=d[i+1]){
				cout<<0<<endl;
				flag=1;
				break;
			}
			if(c[i+1]-1ll==c[i]){
				ans=(ans*(((v-1)*v)+1))%mod; 
			}else{
				ll ik=ksm(c[i+1]-c[i]);
				ik=(ik*ik)%mod;
				ans=(ans*ik)%mod;
			}
		}
		if(flag){
			continue;
		}
		cout<<ans<<endl;
	}
	return 0;
}
/*
1
10 11 2
10 2
7 2
7 2
2 2
3 2
4 2
10 2
7 2
10 2
3 2
3 2

*/
