#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxm=1e5+5;
const ll mod=1e9+7;

struct NODE{ int x,y; }a2[maxm];
bool cmp(NODE a,NODE b){ return a.x<b.x; }

ll Pow_(ll x,ll y){
	ll s=1;
	while(y){
		if(y&1) s*=x,s%=mod;
		x*=x,x%=mod;
		y>>=1;
	}
	return s;
}

NODE a[maxm];
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int t; cin>>t;
	while(t--){
		int n,m2; ll v; cin>>n>>m2>>v;
		for(int i=1;i<=m2;i++)
			cin>>a2[i].x>>a2[i].y;
		sort(a2+1,a2+m2+1,cmp);
		bool ok=1;
		for(int i=2;i<=m2;i++)
			if(a2[i].x==a2[i-1].x&&a2[i].y!=a2[i-1].y){
				ok=0;
				break;
			}
		if(!ok){
			cout<<"0\n";
			continue;
		}
		int m=0;
		for(int i=1;i<=m2;i++)
			if(a2[i].x!=a2[i-1].x) a[++m]=a2[i];
//		cout<<" ------------- \n";
//		cout<<m<<"\n";
//		for(int i=1;i<=m;i++){
//			cout<<a[i].x<<" "<<a[i].y<<"\n";
//		}
		ll ans=1;
		if(a[1].x!=1) ans*=Pow_(v*v%mod,a[1].x-1),ans%=mod;
		for(int i=2;i<=m;i++){
			if(a[i-1].x+1==a[i].x) ans*=(v*v%mod+mod-(v-1))%mod,ans%=mod;
			else ans*=Pow_(v*v%mod,a[i].x-a[i-1].x),ans%=mod;
		}
		if(a[m].x!=n) ans*=Pow_(v*v%mod,(n-a[m].x)),ans%=mod;
		cout<<ans<<"\n";
	}
	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
*/
