#include<bits/stdc++.h> 
#define ri register int
#define ll long long
#define mkp make_pair
using namespace std;
const int maxn=1e5+7;
const int mod=1e9+7;
int n,m,v;
pair<int,int>lim[maxn];
ll qpow(ll a,ll b,ll p){
	ll ans=1;
	for(;b;b>>=1,a=a*a%p)if(b&1)ans=ans*a%p;
	return ans;
}
void solve(){
	cin>>n>>m>>v;
	for(ri i=1;i<=m;i++)cin>>lim[i].first>>lim[i].second;
	sort(lim+1,lim+1+m);
	m=unique(lim+1,lim+1+m)-lim-1;
	for(ri i=1;i<m;i++){
		if(lim[i].first==lim[i+1].first){
			cout<<0<<endl;
			return;
		}
	}
	ll ans=1;
	ans=ans*qpow(v,2*(lim[1].first-1),mod)%mod;
	ans=ans*qpow(v,2*(n-lim[m].first),mod)%mod;
	for(ri i=1;i<m;i++){
		ll tmp=qpow(v,2*(lim[i+1].first-lim[i].first),mod);
		tmp=(tmp-qpow(v,lim[i+1].first-lim[i].first,mod)+mod)%mod;
		tmp=(tmp+qpow(v,lim[i+1].first-lim[i].first-1,mod))%mod;
		ans=ans*tmp%mod;
	}
	cout<<ans<<endl;
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	int T;cin>>T;
	while(T--)solve();
	return 0;
}
/*
3
2 1 2
1 1
2 2 2
1 1
2 2
2 2 2
1 1
1 2

*/
