#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5 + 10, mod = 1e9 + 7;
bool Mst;
int n, m, v, f[N];
PII p[N]; 
int qmi(int a, int b) {
	int res = 1;
	while(b) {
		if(b & 1) res = 1ll * res * a % mod;
		a = 1ll * a * a % mod, b >>= 1;
	}
	return res;
}
void work() {
	cin >> n >> m >> v;
	for(int i = 1, v; i <= m; i ++) cin >> p[i].x >> p[i].y;
	sort(p + 1, p + m + 1);
	for(int i = 1; i < m; i ++)
		if(p[i].x == p[i + 1].x && p[i].y != p[i + 1].y) return cout << 0 << '\n', void();
	m = unique(p + 1, p + m + 1) - p - 1;
	f[1] = qmi(v, 2 * (p[1].x - 1));
	for(int i = 2; i <= m; i ++) {
		f[i] = 1ll * f[i - 1] * (qmi(v, 2 * (p[i].x - p[i - 1].x)) - 1ll * qmi(v, p[i].x - p[i - 1].x - 1) * (v - 1) % mod) % mod;
	}
//	cout << m << ' ' << pw(n - p[m].x) * 2 << '\n';
	cout << (1ll * f[m] * qmi(v, (n - p[m].x) * 2) % mod + mod) % mod << '\n';
}
bool Med;
signed main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0);
	cerr << (abs(&Mst - &Med) / 1048576.0) << "Mb\n";
	int T = 1; cin >> T;
	while(T --) work();

	return 0;
}


