#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1000000007;
ll n,m,T,v,ans,k[100005],flag;
ll R1,mov,cnt;
struct R{
	ll c,d;
}R2[100005];
bool cmp(R a,R b){
	if(a.c == b.c)return a.d < b.d;
	return a.c < b.c;
}
ll POW(ll m,ll p){
	if(p == 0)return 1;
	if(p == 1)return m%MOD;
	ll k = POW(m,p/2)%MOD;
	if(p % 2 == 0){
		return k*k % MOD;
	}
	else{
		return (m%MOD)*(k*k % MOD) % MOD;
	}
}
bool SAME(R a,R b){
	return a.c == b.c and a.d == b.d;
}
ll F(ll x){
	return POW(v,(x-1))*(v-1)%MOD;
}
ll inv(ll k){
	return POW(k,MOD-2)%MOD;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		R1 = 0;
		flag=0;
		cnt =0;
		scanf("%lld%lld%lld",&n,&m,&v);
		ans = POW(v*v,n-1)%MOD;
		for(int i=1;i<=m;i++){
			scanf("%lld%lld",&R2[i].c,&R2[i].d);
		}
		sort(R2+1,R2+m+1,cmp);
		mov = 0;
		for(int i=2;i+mov<=m;i++){
			R2[i] = R2[i+mov];
			while(SAME(R2[i],R2[i-1])){
				mov++;
				R2[i] = R2[i+mov];
			}
		}
		m -= mov;
		for(int i=2;i<=m;i++){
			if(R2[i].c == R2[i-1].c){
				ans = -1;
				break;
			}
			k[++cnt] = R2[i].c - R2[i-1].c;
		}
		if(ans == -1)printf("0\n");
		else{
			for(int i=1;i<=cnt;i++){
				ans = ans*inv(POW(v,2*k[i]));
				ans %= MOD;
				ans += MOD;
				ans %= MOD;
				ans = ans*(POW(v,2*k[i])-F(k[i]));
				ans %= MOD;
				ans += MOD;
				ans %= MOD;
			}
			printf("%lld\n",ans);
		}
	}

	return 0;
}
//±ČT1 Ez 10000x 
/*
4
2 1 2
1 1
2 2 2
1 1
2 2
2 2 2
1 1
1 2
10 5 2
2 2
3 2
4 2
7 2
10 2
*/
