#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100100;
const int mod = 1e9 + 7;
int T,n,m,v;
int c[N],d[N];
struct node{
	int c,d;
}p[N];
struct rule{
	int id,val;
}a[N];
bool cmp(node a,node b){
	return a.c<b.c;
}
bool cmpid(rule a,rule b){
	return a.id<b.id;
}
int qp(int k,int p){
	if(p==0) return 1;
	int tmp=qp(k,p/2);
	if(p%2) return (tmp*tmp%mod)*k%mod;
	else return tmp*tmp%mod;
}
int getid(int k){
	int l=1,r=m,ans=0;
	while(l<=r){
		int mid=l+r>>1;
		if(p[mid].c>=k) ans=mid,r=mid-1;
		else l=mid+1;
	}
	return ans;
}
int dp[N];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	while(T--){
		cin>>n>>m>>v;
		v%=mod;
		for(int i=1;i<=m;i++) cin>>c[i]>>d[i],p[i].c=c[i],p[i].d=d[i];
		sort(p+1,p+1+m,cmp);
		for(int i=1;i<=m;i++){
			a[i].id=getid(c[i]);
			a[i].val=d[i];
		}
		sort(a+1,a+1+m,cmpid);
		dp[0]=qp(v,2*(p[a[1].id].c-1));
		bool tag=0;
		for(int i=1;i<m;i++){
			int lst=i;
			while(a[i+1].id==a[lst].id && i+1<=m && a[i+1].val==a[lst].val) dp[i]=dp[lst-1],i++;
			if(a[i+1].id==a[lst].id && i<=m){
				tag=true;
				break;
			}else if(i==m) break;
			int l=p[a[i+1].id].c-p[a[i].id].c;
			dp[i]=dp[i-1];
			(dp[i]*=((qp(v,2*l)-qp(v,l-1)*(v-1)%mod)%mod+mod)%mod)%=mod;
		}
		if(tag) cout<<0<<'\n';
		else cout<<(dp[m-1]*qp(v,(n-p[a[m].id].c+1)*2)%mod)*(qp(v*v%mod,mod-2))%mod<<'\n';
	}
	return 0;
}
