#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const ll MOD=1e9+7; 
const int M=1e5+5;
ll qpow(ll A,ll B)
{
	ll ans=1;
	while(B)
	{
		if(B&1) (ans*=A)%=MOD;
		B>>=1;
		A=A*A%MOD;
	}
	return ans;
}
pair<ll,ll> a[M];
void work()
{
	ll n,m,v;cin>>n>>m>>v;
	for(ll i=1;i<=m;i++) cin>>a[i].fi>>a[i].se;
	sort(a+1,a+m+1);
	for(ll i=1;i<m;i++) if(a[i].fi==a[i+1].fi&&a[i].se!=a[i+1].se) {cout<<0<<endl;return ;}
	ll ans=qpow(v*v%MOD,a[1].fi-1);
	for(ll i=2;i<=m;i++){
		if(a[i].fi==a[i-1].fi) continue;
		ans=ans*((qpow(v*v%MOD,a[i].fi-a[i-1].fi)-qpow(v,a[i].fi-a[i-1].fi-1)*(v-1)%MOD+MOD)%MOD)%MOD;
	}
	ans=ans*qpow(v*v%MOD,n-a[m].fi)%MOD;
	cout<<ans<<endl;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	
	int T;cin>>T;
	while(T--) work();
	return 0;
}
/*
797858048
*/
