#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
long long dp[N];
struct pos {
	int ind, v;
	friend bool operator < (pos a, pos b) {
		return a.ind < b.ind;
	}
	friend bool operator == (pos a, pos b) {
		return a.ind == b.ind && a.v == b.v;
	}
}p[N];
long long fast_pow (long long base, int zs) {
	base %= mod;
	int res = 1;
	while (zs) {
		if (zs & 1) res = 1ll * res * base % mod;
		base = 1ll * base * base % mod;
		zs >>= 1;
	}
	return res;
}
void solve () {
	int n, m;
	long long v, T;
	scanf("%d%d%lld", &n, &m, &v);
	for (int i = 1; i <= m; i++) 
		scanf("%d%d", &p[i].ind, &p[i].v);
	T = v * v % mod;
	sort (p + 1, p + 1 + m);
	m = unique(p + 1, p + 1 + m) - p - 1;
	for (int i = 1; i <= m; i++) 
		if (p[i].ind == p[i - 1].ind) 
			return void (printf("0\n"));
	dp[1] = fast_pow(T, p[1].ind - 1);
	for (int i = 2; i <= m; i++) {
		dp[i] = (fast_pow(T, p[i].ind - p[i - 1].ind) - (fast_pow(v, p[i].ind - p[i - 1].ind - 1) * (v - 1) % mod)) * dp[i - 1] % mod;
	}
	dp[m + 1] = dp[m] * fast_pow(T, n - p[m].ind) % mod;
	printf("%lld\n", (dp[m + 1] + mod) % mod);
}
signed main () {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int t;
	scanf("%d", &t);
	while (t--) solve();
	return 0;
}
