#include<bits/stdc++.h>
#define ll long long
#define N 100005
using namespace std;
int t;
ll n,m,v,c[N],d[N],mod=1e9+7;
struct A{
	ll c,d;
}a[N];
bool cmp(A x,A y){
	return x.c<y.c;
}
ll qpow(ll a,ll x){
	ll res=1;
	for(;x;a=a*a%mod,x/=2)
		if(x%2)res=res*a%mod;
	return res;
}
void solve(){
	scanf("%lld%lld%lld",&n,&m,&v);
	for(int i=1;i<=m;i++){
		scanf("%lld%lld",&a[i].c,&a[i].d);
	}
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<m;i++){
		if(a[i].c==a[i+1].c&&a[i].d!=a[i+1].d){
			printf("0\n");
			return;
		}
	}
	ll ans=qpow(v,2*a[1].c-2);
	for(int i=1;i<m;i++){
		if(a[i].c==a[i+1].c)continue;
		ll len=a[i+1].c-a[i].c;
		ll res=qpow(v,2*len);
		ll res2=(qpow(v,len)-qpow(v,len-1)+mod)%mod;
		res=(res-res2+mod)%mod;
		ans=ans*res%mod;
	}
	ans=ans*qpow(v,2*n-2*a[m].c)%mod;
	printf("%lld\n",ans);
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&t);
	while(t--)solve();
	return 0;
}
