#include<bits/stdc++.h>
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define rep(i,a,b) for(int i=a,i##e=b;i<=i##e;++i)
#define per(i,a,b) for(int i=a,i##e=b;i>=i##e;--i
#define rsn(i,p) for(int i=h[p];i;i=x[i])
using namespace std;
pair<int,int>a[100001],b[100001];
int f[100001];
const int M=1e9+7;
inline int qpow(int x,int y){
	int r=1;
	while(y){
		if(y&1)r=1ll*r*x%M;
		x=1ll*x*x%M;
		y>>=1;
	}
	return r;
}
inline int ny(int x){
	return qpow(x,M-2);
}
void sol(){
	int n,m,v;
	cin>>n>>m>>v;
	rep(i,1,m){
		cin>>a[i].first>>a[i].second;
	}
	sort(a+1,a+1+m);
	bool ok=1;
	int mm=0;
	for(int i=1;i<=m;++i){
		int j=i;
		while(j<m&&a[j+1].first==a[i].first){
			++j;
			if(a[j].second!=a[i].second){
				ok=0;
			}
		}
		b[++mm]=a[i];
//		cout<<"push "<<a[i].first<<' '<<a[i].second<<' '<<i<<' '<<j<<'\n'; 
		i=j;
	}
	if(!ok){
		cout<<0<<'\n';
		return;
	}
//	cout<<'\n';
//	rep(i,1,mm){
//		cout<<b[i].first<<' '<<b[i].second<<'\n';
//	}
//	return;
	m=mm;
	swap(a,b);
	f[1]=qpow(v,2*(a[1].first-1));
//	cout<<f[1]<<' ';
	int inv=ny(v);
	int invv=ny((inv+M-1)%M);
	rep(i,2,m){
		int len=a[i].first-a[i-1].first-1;
		f[i]=0;
		f[i]=(1ll*qpow(v,2*a[i].first-2*a[i-1].first-2)*f[i-1]%M)*((v+(M+qpow(inv,len)-1)%M*1ll*invv%M)%M)%M;
		f[i]=1ll*f[i]*(v-1)%M;
//		rep(k,-1,len-1){
//			f[i]+=1ll*f[i-1]*qpow(v,-k+2*a[i].first-2*a[i-1].first-2)%M*(v-1)%M;
//			if(f[i]>=M)f[i]-=M;
//		}
		f[i]+=1ll*f[i-1]*qpow(v,len)%M;
		if(f[i]>=M)f[i]-=M;
	}
	f[m]=1ll*f[m]*qpow(v,2*(n-a[m].first))%M;
	cout<<f[m]<<'\n';
}
int main(){
	fre(assign);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while(t--)sol(); 
	return 0;
}
/*ام*/ 
