#include<bits/stdc++.h>
#define ll long long

using namespace std;

const ll N = 1e5+5,mod = 1e9+7;

struct node{
	ll c,d;
}q[N];

bool cmp(node x,node y){
	return x.c<y.c;
}
ll T;
ll n,m,v; 

ll ksm(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
int 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;
		
		for(int i=1;i<=m;i++)
			cin>>q[i].c>>q[i].d;
		
		bool tmp=0;
		sort(q+1,q+m+1,cmp);
		for(int i=1;i<m;i++){
			if(q[i].c==q[i+1].c && q[i].d!=q[i+1].d){
				tmp=1;
				break;
			}
		}
		if(tmp){
			cout<<0<<"\n";
			continue;
		}
		
		q[m+1].c=n;
		q[0].c=1;
		ll ans=1;
		ans=ans*ksm(v,(q[1].c-q[0].c)*2)%mod;
		for(int i=2;i<=m;i++){
			if(q[i].c==q[i-1].c)continue;
			ans=ans*((ksm(v,(q[i].c-q[i-1].c)*2)-ksm(v,q[i].c-q[i-1].c-1)*(v-1)%mod+mod)%mod)%mod;
		}
		ans=ans*ksm(v,(q[m+1].c-q[m].c)*2)%mod;
		cout<<ans<<"\n";
	}
	return 0;
}
