#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int N=100005,MOD=(1e9+7);
int T,n,m,v,f[N],vis[N];
struct node{
	int c,d;
}a[N];
bool cmp(node aa,node bb){
	return aa.c<bb.c;
}
int ksm(int x,int k){
	int ans=1;
	while(k){
		if(k&1){
			ans=ans*x%MOD;
		}
		x=x*x%MOD;
		k=k/2;
	}
	return ans;
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--){
		cin>>n>>m>>v;
//		cout<<n<<" "<<m<<" "<<v<<" "; 
		for(int i=1;i<=m;i++){
			cin>>a[i].c>>a[i].d;
			vis[i]=0;	
		}
		sort(a+1,a+1+m,cmp);
		int fla=0;
		for(int i=1;i<m;i++){
			if(a[i].c==a[i+1].c){
				vis[i]=1;
			}
			if(a[i].c==a[i+1].c&&a[i].d!=a[i+1].d){
				fla=1;
				break;
			}
		}
		if(fla==1){
			cout<<0<<"\n";
			continue;
		}
		int qwq=1,awa=m;
		for(int i=1;i<=awa&&qwq<=awa;i++){
			while(vis[qwq]==1&&qwq<=awa){
				qwq++;
			}
			if(qwq==awa+1)break;
			m=i;
			a[i]=a[qwq];
			qwq++;
		}
		f[1]=ksm(v,2*(a[1].c-1));
		for(int i=2;i<=m;i++){
			int pp=a[i].c-a[i-1].c;
			f[i]=f[i-1]*((ksm(v,2*pp)-(ksm(v,pp-1)*(v-1)%MOD)+MOD)%MOD)%MOD; 
		}
		cout<<f[m]*ksm(v,(n-a[m].c)*2)%MOD<<"\n";
	}
}
