#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int N=1e5+10,mod=1e9+7;
int ksm(int a,int x){
	int ans=1;
	for(;x;x>>=1,a=1ll*a*a%mod)if(x&1)ans=1ll*ans*a%mod;
	return ans;
} 
int n,m,V;
pair<int,int> a[N];
void solve(){
	cin>>n>>m>>V;
	for(int i=1;i<=m;i++)cin>>a[i].first>>a[i].second;
	sort(a+1,a+m+1);
	int ans=1;
	for(int i=1;i<m;i++){
		if(a[i].first==a[i+1].first){
			if(a[i].second!=a[i+1].second){
				cout<<"0"<<endl;
				return;
			}
			continue;
		}
		int u=a[i].first,v=a[i+1].first;
		int k=(ksm(V,(v-u)*2)-1ll*ksm(V,v-u-1)*(V-1)%mod+mod)%mod;
		ans=1ll*ans*k%mod;
	}
	int k=1ll*ksm(V,(a[1].first-1)*2)*ksm(V,(n-a[m].first)*2)%mod;
	ans=1ll*ans*k%mod;
	cout<<ans<<endl;
	
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;cin>>T;
	while(T--)solve();
}

