#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;
const int MAXM = 1e5 + 5;
int T, m; ll n, v, ans;
struct Node { int c, d; } a[MAXM];

ll qpow(ll x, ll y) {
	ll res = 1;
	for ( ; y; y /= 2, x = x * x % MOD)
		if (y & 1)
			res = res * x % MOD;
	return res;
}

int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	scanf("%d", &T);
	while (T--) {
		scanf("%lld%d%lld", &n, &m, &v);
		for (int i = 1; i <= m; i++) scanf("%d%d", &a[i].c, &a[i].d);
		sort(a + 1, a + 1 + m, [](Node x, Node y) { return x.c != y.c ? x.c < y.c : x.d < y.d; });
		bool flag = false;
		for (int i = 2; i <= m; i++) {
			if (a[i].c == a[i - 1].c && a[i].d != a[i - 1].d) {
				flag = true;
				break;
			}
		}
		if (flag) { printf("0\n"); continue; }
		ans = 1;
		ans = ans * qpow(v, 2 * (a[1].c - 1)) % MOD;
		for (int i = 2; i <= m; i++) {
			if (a[i].c == a[i - 1].c) continue;
			ans = ans * (qpow(v, 2 * (a[i].c - a[i - 1].c)) - qpow(v, a[i].c - a[i - 1].c - 1) * (v - 1) % MOD + MOD) % MOD;
		}
		ans = ans * qpow(v, 2 * (n - a[m].c)) % MOD;
		printf("%lld\n", ans);
	}
	return 0;
}

