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

long long read() {
	long long x = 0, k = 1;
	char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') k = -1, c = getchar();
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return x * k;
}

const int N = 1e5 + 7;
const long long mod = 1e9 + 7;

struct LZY {
	long long pos, val;
	bool operator < (const LZY &x) const {
		return pos < x.pos;
	}
};

long long n, m, v;
LZY t[N];
long long pw0[N], pw1[N];

long long getPow(long long x) {
	return pw0[x % 100000] * pw1[x / 100000] % mod;
}

void solve() {
	n = read(), m = read(), v = read();
	for (int i = 1; i <= m; i ++)
		t[i].pos = read(), t[i].val = read();
	pw0[0] = pw1[0] = 1;
	for (int i = 1; i <= 100000; i ++) pw0[i] = pw0[i - 1] * v % mod;
	for (int i = 1; i <= 100000; i ++) pw1[i] = pw1[i - 1] * pw0[100000] % mod;
	int l = 1; long long ans = 1;
	sort(t + 1, t + m + 1);
	for (int i = 1; i <= m; i ++) {
		if (i > 1 && t[i].pos == t[i - 1].pos) {
			if (t[i].val != t[i - 1].val) {
				cout << 0 << '\n';
				return ;
			}
			continue;
		}
		long long num = 0;
		if (i == 1) num = getPow(2 * (t[i].pos - l));
		else num = (getPow(2 * (t[i].pos - l)) - getPow(t[i].pos - l - 1) * (v - 1) % mod + mod) % mod;
//		printf("(%d, %d) : num = %lld\n", l, t[i].pos, num);
		(ans *= num) %= mod;
		l = t[i].pos;
	}
	if (l < n) (ans *= getPow(2ll * (n - l))) %= mod;
//	printf("(l, n) = (%d, %d)\n", l, n);
//	printf("getPow(%lld) = %lld\n", 2ll * (n - l), getPow(2 * (n - l)));
	cout << ans << '\n';
}

signed main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int t = 1;
	t = read();
	while (t --)
		solve();
	return 0;
}
/*
3
2 1 2
1 1
2 2 2
1 1
2 2
2 2 2
1 1
1 2

//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
*/ 
