#include<bits/stdc++.h>
#define int long long
#define Pair pair<int,int>
using namespace std;
const int MAXN=1e5+5;
const int mod=1e9+7;
int n,m,V;
Pair a[MAXN];
inline int ksm(int a,int b){
	int cnt=1;
	while(b){
		if(b&1)cnt=cnt*a%mod;
		a=a*a%mod;b>>=1;
	}
	return cnt;
}
inline void solve(){
	cin>>n>>m>>V;
	for(int i=1;i<=m;i++)cin>>a[i].first>>a[i].second;
	sort(a+1,a+m+1);m=unique(a+1,a+m+1)-(a+1);
	for(int i=2;i<=m;i++)if(a[i].first==a[i-1].first){
		cout<<"0\n";return ;
	}
	int ans=ksm(V,2*(a[1].first-1))*ksm(V,2*(n-a[m].first))%mod;
	for(int i=2;i<=m;i++){
		int del=ksm(V,2*(a[i].first-a[i-1].first));
		(del+=(mod-ksm(V,a[i].first-a[i-1].first-1)*(V-1)%mod))%=mod;
		(ans*=del)%=mod;
	}
	cout<<ans<<"\n";
}
#define Fopen(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
signed main(){
	Fopen("assign");
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	int T;cin>>T;while(T--)solve();
}
