#include <bits/stdc++.h>
using namespace std;
inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); }
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}
const int N = 1e5 + 10, mod = 1e9 + 7;
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int sub(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
int n, m, v;
int qpow(int a, int k) {
	int res = 1;
	while(k) {
		if(k & 1) res = 1ll * res * a % mod;
		a = 1ll * a * a % mod;
		k >>= 1;
	}
	return res;
}
struct node {
	int c, d;
} p[N];
bool cmp(node x, node y) { return x.c < y.c; }
void MAIN() {
	n = read(), m = read(), v = read();
	for(int i = 1; i <= m; i++) {
		p[i].c = read(), p[i].d = read();
	}
	sort(p + 1, p + 1 + m, cmp);
	int pw2 = 1ll * v * v % mod;
	int res = qpow(pw2, n - p[m].c);
//	cout << pw2 << " " << res << endl;
//	int t = qpow(1ll * v * v % mod);
	for(int i = m - 1; i; i--) {
		int k = res;
		if(p[i + 1].c == p[i].c && p[i + 1].d != p[i].d) {
			printf("0\n");
			return;
		}
		if(p[i + 1].c == p[i].c) continue;
		res = 1ll * k * (v - 1) % mod * v % mod * qpow(1ll * v * v % mod, p[i + 1].c - p[i].c - 1) % mod;
		if(p[i + 1].c == p[i].c + 1) {
			res = add(res, k);
		}
		else {
			int len = p[i + 1].c - p[i].c - 1;
			int t2 = qpow(v, len - 1);
			res = add(res, 1ll * k * v % mod * sub(qpow(v, 2 * (len - 1) % (mod - 1)), t2) % mod * pw2 % mod);
			res = add(res, 1ll * k * v % mod * t2 % mod * add(1ll * (v - 1) * v % mod, 1) % mod);
		}
//		cout << i << endl;
	}
	res = 1ll * res * qpow(1ll * v * v % mod, p[1].c - 1) % mod;
	printf("%d\n", res);
//	exit(0);
}
int main() {
//	if(system("fc assign.out assign3.ans")) return 0;
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int T = read();
	while(T--) {
		MAIN();
	}
	return 0;
}
