#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7, N = 1e5 + 5;
int T, n, m, V;
struct node {
	int c, d;
	bool operator< (const node& u) const {return c < u.c;}
} a[N];
inline ll Pow(ll a, ll x) { //a^x
	ll ret = 1;
	for (ll c = a; x; (c *= c) %= mod, x >>= 1)
		if (x & 1) (ret *= c) %= mod;
	return ret;
}
int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d%d", &n, &m, &V);
		for (int i = 1; i <= m; i++)
			scanf("%d%d", &a[i].c, &a[i].d);
		sort(a + 1, a + m + 1);
		bool flag = true;
		ll ans = 1;
		for (int i = 1; i <= m; i++) {
			if (a[i].c == a[i-1].c && a[i].d != a[i-1].d) {
				flag = false;
				break;
			}
			if (a[i].c == a[i-1].c || a[i].c == 1) continue;
			int len = a[i].c - a[i-1].c + 1;
			if (i == 1) (ans *= Pow(V, 2*a[i].c-2)) %= mod;
			else (ans *= (Pow(V, 2*len-2)-(Pow(V, len-2)*(V-1))%mod)%mod) %= mod;
		}
		if (a[m].c < n) (ans *= Pow(V, 2*(n-a[m].c))) %= mod;
		if (flag) printf("%lld\n", (ans%mod+mod)%mod);
		else printf("0\n");
	}
	return 0;
}
