#include <bits/stdc++.h>
#define ll long long
#define pir pair <ll, ll>
#define mkp make_pair
#define fi first
#define se second
#define pb emplace_back
using namespace std;

void rd(ll &x) {
	char ch; bool f = 0;
	while(!isdigit(ch = getchar()))
		if(ch == '-') f = 1;
	x = ch - '0';
	while(isdigit(ch = getchar()))
		x = (x << 1) + (x << 3) + ch - '0';
	if(f) x = -x;
}

const ll maxn = 1e5 + 10, mod = 1e9 + 7;

ll power(ll a, ll b = mod - 2) {
	ll s = 1;
	while(b) {
		if(b & 1) s = s * a %mod;
		a = a * a %mod, b >>= 1;
	} return s;
}

ll t, n, m, v, ans;
pir p[maxn];

void solve() {
	rd(n), rd(m), rd(v);
	for(ll i = 1; i <= m; i++) rd(p[i].fi), rd(p[i].se);
	sort(p + 1, p + 1 + m);
	for(ll i = 1; i < m; i++)
		if(p[i].fi == p[i + 1].fi && p[i].se != p[i + 1].se)
			return puts("0"), void();
	ans = power(v, (p[1].fi - 1) * 2 + (n - p[m].fi) * 2);
//	if(t == 0)
//		puts("GG");
	for(ll i = 1; i < m; i++) {
		if(p[i].fi == p[i + 1].fi) continue;
		ll res = power(v, (p[i + 1].fi - p[i].fi) * 2);
		res = (res + mod - power(v,
		 p[i + 1].fi - p[i].fi - 1) * (v - 1) %mod) %mod;
		ans = ans * res %mod;
	} printf("%lld\n", ans);
}

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