#include<bits/stdc++.h>
#define LL long long

using namespace std;

const int mod = 1e9 + 7;

const int maxn = 1e5 + 10;

int inline read() {
	int x = 0; char ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x;
}

int pow_mod(int a, int k) {
	int ret = 1;
	while (k) {
		if (k & 1) ret = (LL) ret * a % mod;
		a = (LL)a * a % mod;
		k >>= 1;
	}
	return ret;
}

int n, m, v;

struct Point{
	int p, x;
};

Point a[maxn];

void clear() {
	for (int i = 1; i <= m; i++) a[i] = Point{0, 0};
}

int cal(int len, int op) {
	// len >= 1
	if (op == 1) { // in the middle
		if (len == 1) return 1;
		int sum = pow_mod(v, 2*(len-1));
		int res = (LL)pow_mod(v, len-2) * (v-1) % mod;
		return ((LL)sum - res + mod) % mod;
	} else { // at the edge
		if (len == 1) return 1;
		return pow_mod(v, 2*(len-1));
	}
}

int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	
	int T = read();
	while (T--) {
		n = read(), m = read(), v = read();
		clear();
		for (int i = 1; i <= m; i++) {
			int p = read(), x = read();
			a[i] = Point{p, x};
		}
		sort(a+1, a+1+m, [&] (const Point &a, const Point &b) {
			return a.p < b.p;
		});
		
		bool ok = true;
		for (int i = 1; i+1 <= m; i++) {
			if (a[i].p == a[i+1].p && a[i].x != a[i+1].x) {
				ok = false;
			}
		}
		if (!ok) {
			cout << 0 << endl;
			continue;
		}
		
		int ans = 1;
		
		ans = (LL)ans * cal(a[1].p, 0) % mod;
		ans = (LL)ans * cal(n - a[m].p + 1, 0) % mod;
		for (int i = 1; i+1 <= m; i++) {
			ans = (LL)ans * cal(a[i+1].p - a[i].p + 1, 1) % mod;
		}
		cout << ans << endl;
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}
