#include <bits/stdc++.h>
#define pii pair<int,int>
#define mkp make_pair
#define fi first
#define se second
using namespace std;

const int N=1e5+7,mod=1e9+7;
int T,n,m,v;
pii a[N];
int qpow(int a,int b){
	if(b<0) return 0;
	int ans=1;
	while(b){
		if(b&1) ans=1ll*ans*a%mod;
		a=1ll*a*a%mod;
		b=b>>1;
	}
	return ans;
}
void Subt(){
	scanf("%d%d%d",&n,&m,&v);
	int vv=1ll*v*v%mod;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&a[i].fi,&a[i].se);
	}
	sort(a+1,a+m+1);
	int ans=1;
	a[0].fi=1;
	for(int i=1;i<=m;i++){
		if(i>1&&a[i].fi==a[i-1].fi){
			if(a[i].se!=a[i-1].se) ans=0;
		}else{
			int C=qpow(vv,a[i].fi-a[i-1].fi);
			int D=1ll*qpow(v,a[i].fi-a[i-1].fi-1)*(v-1)%mod;
			if(i>1) C=(C-D+mod)%mod;
			ans=1ll*ans*C%mod;
			//printf("C! %d\n",C);	
		}
	}
	ans=1ll*ans*qpow(vv,n-a[m].fi)%mod;
	printf("%d\n",ans);
}
signed main(){
	freopen("assign.in" ,"r",stdin );
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--) Subt();
	return 0;
}
