#include<bits/stdc++.h>
#define N 100005
#define int long long
#define mod 1000000007
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
int t,n,m,v,iv;
int ans;
int fpow(int x,int y){
	// cout<<y<<endl;
	int ret=1;
	while(y){
		if(y&1)ret=ret*x%mod;
		y>>=1,x=x*x%mod;
	}
	return ret;
}
pii a[N];
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--){
		cin>>n>>m>>v;
		iv=fpow(v,mod-2);
		for(int i=1;i<=m;i++)cin>>a[i].fi>>a[i].se;
		sort(a+1,a+1+m);
		ans=fpow(v,(a[1].fi-1+n-a[m].fi)*2);
		for(int i=1;i<m;i++){
			int l=a[i+1].fi-a[i].fi+1;
			if(a[i]==a[i+1])continue;
			if(l==1){ans=0;break;}
			if(l==2){
				ans=ans*(1+(v-1)*v%mod)%mod;
			}else	ans=ans*(fpow(v,l-2)+(v-1)*fpow(v,2*l-3)%mod*(fpow(iv,l-1)-1)%mod*fpow(iv-1,mod-2)%mod)%mod;
			// cout<<ans<<endl;
			// cout<<fpow(v,l-2)<<' '<<(v-1)*fpow(v,2*l-3)%mod*(fpow(iv,l-1)-1)%mod*fpow(iv-1,mod-2)%mod<<endl;
			// cout<<fpow(v,2*l-2)<<endl;
		}
		cout<<ans<<'\n';
	}
	return 0;
}