#include <bits/stdc++.h>
#define MOD (1000000007)
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;


ll fpow(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if (b & 1) ans = ans * a % MOD;
		b >>= 1;
		a = a * a % MOD;
	}
	return ans;
}

pii a[100005];

int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) {
		ll n, m, v;
		cin >> n >> m >> v;
		for (int i = 1; i <= m; i++) {
			cin >> a[i].fi >> a[i].se;
		}
		ll ans = 1;
		sort(a+1, a+m+1);
		for (int i = 1; i <= m; i++) {
			if (i != m && a[i].fi == a[i+1].fi && a[i].se != a[i+1].se) {
				cout << 0 << endl;
				goto noanswer;
			}
		}
		m = unique(a+1, a+m+1) - a - 1;
		for (int i = 1; i < m; i++) {
			int len = a[i+1].fi - a[i].fi - 1;
			if (len == 0) {
				ans = ans * ((v * (v-1) + 1) % MOD) % MOD;
			} else {
				ll j = fpow(v, 2 * len + 2) - fpow(v, len) * (v - 1) % MOD;
				j = (j + MOD) % MOD;
				ans = ans * j % MOD;
			}
		}
		ans = ans * fpow(v, 2 * (a[1].fi - 1)) % MOD;
		ans = ans * fpow(v, 2 * (n - a[m].fi)) % MOD;
		cout << ans << endl;
noanswer:
		;
	}
} 
