#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=100010;
const int p=1000000007;
typedef pair<int,int>pii;

inline int qpow(int di,int zhi){
	int res=1;
	while(zhi){
		if(zhi&1){
			res=res*di%p;
		}
		di=di*di%p;
		zhi>>=1;
	}
	return res%p;
}

int n,m,v;
pii a[N];



inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+(ch^48);
		ch=getchar();
	}
	return x;
}

void solve(){
	n=read();m=read();v=read();
	for(int i=1;i<=m;i++){
		a[i].first=read();
		a[i].second=read();
	}
	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){
				continue;
			}else{
				cout<<"0\n";
				return;
			}
		}
		int gap=a[i+1].first-a[i].first-1;
		int sol=qpow(v,gap*2+2)-qpow(v,gap)*(v-1)%p;
//		int sol=qpow(v,gap*2+2)-qpow(v,gap);
		while(sol<0){
			sol+=p;
		}
		while(sol>=p){
			sol-=p;
		}
		ans=ans*sol%p;
	}
	int pre=qpow(v,(a[1].first-1)*2);
	int suc=qpow(v,(n-a[m].first)*2);
	ans=ans*pre%p*suc%p;
	cout<<ans<<"\n";
	return;
}


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;
	T=read();
	while(T--){
		solve();
	}
	return 0;
}

