#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MX=1e5+5,mod=1e9+7;
ll t,n,m,v,ans;
pair<ll,ll> pa[MX];
ll rd(){
	ll res=0;
	char c=getchar();
	while(c>'9'||c<'0')c=getchar();
	while(c<='9'&&c>='0')res=res*10+c-'0',c=getchar();
	return res;
}
ll fp(ll x,ll y){
	ll res=1;
	while(y){
		if(y&1)res=(res*x)%mod;
		x=(x*x)%mod,y/=2;
	}
	return res;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	t=rd();
	while(t--){
		n=rd(),m=rd(),v=rd();
		bool flag=true;
		ans=1;
		for(int i=1;i<=m;++i){
			pa[i].first=rd(),pa[i].second=rd();
		}
		sort(pa+1,pa+m+1);
		for(int i=2;i<=m;++i){
			if(pa[i].first==pa[i-1].first){
				if(pa[i].second!=pa[i-1].second)flag=false;
				continue;
			}
			ll sum=fp(v,(pa[i].first-pa[i-1].first)*2ll);
			sum=(sum-fp(v,(pa[i].first-pa[i-1].first-1))*(v-1)%mod+mod)%mod;
			ans=(ans*sum)%mod;
		}
		ans=(ans*fp(v,(pa[1].first-1)*2ll))%mod;
		ans=(ans*fp(v,(n-pa[m].first)*2ll))%mod;
		if(flag)printf("%lld\n",ans);
		else puts("0");
	}
	return 0;
}
/*
622513748
547054119
935264382
797858048
656531230
561087816
0
0
0
104354915
*/

