#include<bits/stdc++.h>
using std::cin;
using std::cout;
using ll=long long;
const int M=1e5+10,mod=1e9+7;

ll qpow(ll x,ll k){
	ll res=1;
	while(k){
		if(k&1)res=res*x%mod;
		x=x*x%mod,k>>=1;
	}
	return res;
}

int t,n,m;
ll v,dp[M][2];
struct X{
	int c,d;
	bool operator <(const X &x){
		return c==x.c?d<x.d:c<x.c;
	}
	bool operator ==(const X &x){
		return c==x.c&&d==x.d;
	}
}a[M];

void solve(){
	cin>>n>>m>>v;
	for(int i=1;i<=m;++i)
		cin>>a[i].c>>a[i].d;
	std::sort(a+1,a+m+1);
	for(int i=1;i<m;++i)
		if(a[i].c==a[i+1].c&&a[i].d!=a[i+1].d)
			return void(cout<<"0\n");
	m=std::unique(a+1,a+m+1)-a-1;
	dp[0][0]=qpow(v,2*(a[1].c-1)),dp[0][1]=0;
	for(int i=1;i<m;++i){
		ll x=qpow(v,2*(a[i+1].c-a[i].c)),y=qpow(v,(a[i+1].c-a[i].c-1))*(v-1)%mod;
		dp[i][0]=dp[i-1][0]*(x+mod-y)%mod;
		dp[i][1]=(dp[i-1][1]*x%mod+dp[i-1][0]*y%mod)%mod;
	}
	cout<<dp[m-1][0]*qpow(v,2*(n-a[m].c))%mod<<'\n';
}

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin.tie(0)->sync_with_stdio(0);
	cin>>t;
	while(t--)solve();
	return 0;
}
