#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 5, mod = 1e9 + 7;
int T, n, m, v, ans;
int qpow(int x, int k, int p) {
	x %= mod; 
	int res = 1;
	while(k) {
		if(k & 1)
			res = res * x % p; 
		x = x * x % p, k >>= 1; 
	}
	return res;
}
map<int, int> x;
void clr() {
	x.clear();
	ans = 1;
}
void solve() {
	clr();
	cin >> n >> m >> v;
	for (int i = 1; i <= m; i++) {
		int t, p;
		cin >> t >> p;
		if(x[t] && x[t] != p)
			ans = 0;
		x[t] = p;
	}
	if(!ans) {
		cout << 0 << endl; 
		return ;
	}
	int lst = 0;
	for (map<int, int>::iterator it = x.begin(); it != x.end(); it++) {
		int p = it -> first;
		if(!lst) 
			ans = ans * qpow(v * v % mod, p - lst - 1, mod);
		else
			ans = ans * (qpow(v * v % mod, p - lst, mod) - qpow(v, p - lst - 1, mod) * (v - 1) % mod + mod) % mod; 
		lst = p;
	}
	ans = ans * qpow(v * v % mod, n - lst, mod) % mod; 
	cout << ans << endl; 
}
signed main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	cin >> T;
	while(T--)
		solve();
	return 0;
}
