#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 1e5 + 10;
const LL P = 1e9 + 7;
LL n, m, v;
struct node {
	LL x, y;
	bool operator == (const node &rhs) const {
		return rhs.x == x && rhs.y == y;
	}
} a[N];
LL ksm(LL a, LL b) {
	LL res = 1;
	while(b > 0) {
		if(b & 1) res *= a, res %= P;
		a *= a; a %= P;
		b >>= 1;
	}
	return res;
}
int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int T = 0; cin >> T;
	while(T--) {
		cin >> n >> m >> v;
		for(int i = 1; i <= m; i++) {
			cin >> a[i].x >> a[i].y;
		}
		sort(a + 1, a + m + 1, [](node x, node y) {return x.x < y.x;});
		m = unique(a + 1, a + m + 1) - a - 1;
		LL ans = ksm(v * v % P, a[1].x - 1) * ksm(v * v % P, n - a[m].x) % P;
//		cout << ans << '\n';
		for(int i = 1; i < m; i++) {
//			cout << a[i].x << ' ' << a[i].y << '\n';
			if(a[i + 1].x == a[i].x && a[i + 1].y != a[i].y) {ans = 0; break;}
			ans *= (ksm(v * v % P, a[i + 1].x - a[i].x) - (ksm(v, a[i + 1].x - a[i].x - 1) * (v - 1) % P) % P + P) % P;
//			ans -= ksm(v, a[i + 1].x - a[i].x - 1) * (v - 1) % P * ksm(v * v % P, a[i].x - 1) % P * ksm(v * v % P, n - a[i + 1].x) % P; 
			ans = (ans % P + P) % P;
		}
		cout << ans << '\n';
	}
	return 0;
}
