#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
int n, m, v, dp[100010], ans;
struct tt {
	int c, d;
}a[100010];
int cmp(tt a, tt b) {
	return a.c != b.c ? a.c < b.c : a.d < b.d;
}
int ksm(int x, int y) {
	int sum = 1;
	while (y) {
		if (y % 2 == 1) {
			sum = sum * x % mod;
		}
		x = x * x % mod;
		y /= 2;
	}
	return sum;
}
void solve() {
	cin >> n >> m >> v;
	for (int i = 1; i <= m; i++) {
		scanf("%lld%lld", &a[i].c, &a[i].d);
	}
	sort(a + 1, a + 1 + m, cmp);
	ans = 1;
	for (int i = 1; i <= m; i++) {
		if (a[i].c == a[i - 1].c && a[i].d != a[i - 1].d) {
			printf("0");
			return ;
		}
	}
	for (int i = 1; i <= m; i++) {
		if (a[i].c == a[i + 1].c) continue;
		if (a[i].c == a[i + 1].c - 1) {
			dp[i] = (((v - 1) * v % mod) + 1) % mod;
		}else {
			dp[i] = (v * v % mod);
		}
	}
	int lst = 1;
	for (int i = 1; i <= m; i++) {
		if (a[i].c == a[i + 1].c) continue;
		if (lst >= n) break;
		if (a[i].c == n) {
			ans = (ans * ((ksm((v * v) % mod, (a[i].c - 1 - lst + 1))) % mod)) % mod;
			lst = n + 1;
			break;
		}
		if (a[i].c == lst) ans = (ans * dp[i]) % mod;
		else ans = (ans * ((ksm((v * v) % mod, (a[i].c - 1 - lst + 1)) * dp[i] % mod) % mod)) % mod;
		lst = a[i].c + 1;
	}
	if (lst < n) {
		ans = (ans * ((ksm((v * v) % mod, (n - 1 - lst + 1))) % mod)) % mod;
	}
	printf("%lld", ans);
}
signed main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int T;
	cin >> T;
	while (T--) {
		solve();
		printf("\n");
	}
	return 0;
}
