#include<bits/stdc++.h>
#define fir first
#define sec second
using namespace std;
typedef long long ll;
typedef pair<int,int> pir;
const int N=1e5+5;
const ll P=1e9+7;
int T,m;
ll n,V;
pir c[N];
ll qpow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%P;
		a=a*a%P,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;
		int x,y;
		for(int i=1;i<=m;i++) cin>>x>>y,c[i]={x,y};
		sort(c+1,c+m+1);
		ll ans=qpow(V,(c[1].fir-1)*2);
		for(int i=2;i<=m;i++){
			if(c[i].fir==c[i-1].fir){
				if(c[i].sec==c[i-1].sec) continue;
				ans=0;break;
			}
			int len=c[i].fir-c[i-1].fir;
			(ans*=(qpow(V,len*2)-qpow(V,len-1)*(V-1)%P+P)%P)%=P;
		}
		(ans*=qpow(V,(n-c[m].fir)*2))%=P;
		cout<<ans<<'\n';
	}
	return 0;
}
