#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define mod 1000000007
ll t,n,m,k,ans,aa[N],bb[N],a[N],b[N],cnt;
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>q;
ll qpow(ll x,ll y){
	ll res=1;while(y){
		if(y&1) res=(res*x)%mod;
		x=(x*x)%mod,y>>=1;
	}return res;
}int main(){
	freopen("assign.in","r",stdin),freopen("assign.out","w",stdout);
	scanf("%lld",&t);while(t--){
		scanf("%lld%lld%lld",&n,&m,&k),ans=1,cnt=0;
		for(ll i=1;i<=m;i++) scanf("%lld%lld",&aa[i],&bb[i]),q.push({aa[i],bb[i]});
		while(!q.empty()) ++cnt,a[cnt]=q.top().first,b[cnt]=q.top().second,q.pop();
		a[0]=a[1],b[0]=b[1];
		for(ll i=1;i<=m;i++){
			if(a[i]==a[i-1]&&b[i]!=b[i-1]){ans=0;break;}if(a[i]==a[i-1]) continue;
			ans=(ans*((qpow(2,2*(a[i]-a[i-1]))+mod-(qpow(2,a[i]-a[i-1]-1)*(k-1)%mod))%mod))%mod;
		}printf("%lld\n",((((ans*qpow(2,2*(n-a[m])))%mod)*qpow(2,2*(a[1]-1))))%mod);
	}fclose(stdin),fclose(stdout);
	return 0;
} 
