#include<bits/stdc++.h>
#define rep(rp,a,b) for(int rp=a;rp<=b;++rp)
#define per(pr,a,b) for(int pr=a;pr>=b;--pr)
#define Rep(rp,a,b) for(int rp=a;rp<b;++rp)
#define fi first
#define se second
using namespace std;
const int N = 1e5+5, MOD = 1e9+7;
inline int read() {
	int x = 0, f = 1; char ch = 0;
	while (!isdigit(ch)) {ch = getchar(); if (ch == '-') f *= -1;}
	while (isdigit(ch)) x = x*10+(ch^48), ch = getchar();
	return f*x;
}

int powM(int x, int y = MOD-2) {
	int ret = 1;
	while (y) {
		if (y&1) ret = 1ll*ret*x%MOD;
		x = 1ll*x*x%MOD, y >>= 1;
	} return ret;
}

pair<int,int> a[N], b[N];

void solve() {
	int n = read(), m = read(), v = read(), cntn = 0;
	rep (i, 1, m) a[i].fi = read(), a[i].se = read();
	sort(a+1, a+1+m);
	rep (i, 1, m-1) {
		if (a[i].fi == a[i+1].fi) {
			if (a[i].se == a[i+1].se) continue ;
			else return puts("0"), void();
		}
		b[++cntn] = a[i];
	}
	b[++cntn] = a[m];
	int ans = powM(1ll*v*v%MOD, b[1].fi-1+(n-b[cntn].fi));
	rep (i, 1, cntn-1) {
		int tmp = powM(1ll*v*v%MOD, b[i+1].fi-b[i].fi);
		tmp = (tmp-1ll*powM(v, b[i+1].fi-b[i].fi-1)*(v-1)%MOD+MOD)%MOD;
		ans = 1ll*ans*tmp%MOD;
	}
	printf("%d\n", ans);
}

int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int T = read(); while (T --) solve();
	return 0;
}
