#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10, p = 1e9 + 7;
int ttt, n, m, v, tot;
struct lim {
	int c, d;
	bool operator < (lim x) const {return c < x.c; } 
} a[N], b[N];
int qpow(int a, int b = p - 2) {
	int res = 1; a %= p;
	for (; b; b >>= 1, a = a * a % p) if (b & 1) res = res * a % p;
	return res;
}
int tmpcnt;
void solve() {
	cin >> n >> m >> v;
	for (int i = 1; i <= m; i++) {
		cin >> a[i].c >> a[i].d;
	}
	sort(a + 1, a + m + 1);
	tot = 0;
	b[++tot] = a[1];
	for (int i = 2; i <= m; i++) {
		if (a[i].c == a[i - 1].c) {
			if (a[i].d != a[i - 1].d) {
				cout << "0\n";
				return ;
			} 
		} else b[++tot] = a[i];
	}
	int res = 1;
	for (int i = 2; i <= tot; i++) {
		int val = qpow(v * v, b[i].c - b[i - 1].c);
		val = (val + p - qpow(v, b[i].c - b[i - 1].c - 1) * (v - 1) % p);
		res = (res * val) % p;
	}
	res = res * qpow(v * v, b[1].c - 1) % p;
	res = res * qpow(v * v, n - b[tot].c) % p;
	cout << res << '\n';  
}
signed main() {
	freopen("assign.in", "r", stdin); freopen("assign.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> ttt;
	while (ttt--) solve();
}

