#include<bits/stdc++.h>
#define ll long long
//#define int ll
#define MP make_pair
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N=5e5+10,M=1e6+10,mod=1e9+7;
const int B=5e4;
inline void Add(int &x,int y){x+=y;if(x>=mod) x-=mod;}
inline void Del(int &x,int y){x-=y;if(x<0) x+=mod;}
inline int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
inline int del(int x,int y){x-=y;return x<0?x+mod:x;}
int pw1[B+10],pw2[B+10],n,m,v;
inline int pw(int x){return 1ll*pw1[x%B]*pw2[x/B]%mod;}
pii a[N];
void solve(){
	cin>>n>>m>>v;
	for(int i=1;i<=m;i++) cin>>a[i].fi>>a[i].se;
	sort(a+1,a+m+1);
	for(int i=1;i<m;i++) if(a[i].fi==a[i+1].fi&&a[i].se!=a[i+1].se) return cout<<0<<'\n',void();
	pw1[0]=1;for(int i=1;i<=B;i++) pw1[i]=1ll*pw1[i-1]*v%mod;
	pw2[0]=1;for(int i=1;i<=B;i++) pw2[i]=1ll*pw2[i-1]*pw1[B]%mod;
	int ans=1;
	for(int i=1;i<m;i++) if(a[i].fi!=a[i+1].fi){
		int x=a[i].fi,y=a[i+1].fi;
		int res=del(pw(2*(y-x)),pw(y-x));
		Add(res,pw(y-x-1));
		ans=1ll*ans*res%mod;
	}
	int k=a[1].fi-1;
	ans=1ll*ans*pw(2*k)%mod;
	k=n-a[m].fi;
	ans=1ll*ans*pw(2*k)%mod;
	cout<<ans<<'\n';
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T;cin>>T;
	while(T--) solve();
	return 0;
}

