#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

constexpr int mod = (int) 1e9 + 7;

i64 power(i64 x, i64 e) {
	i64 y = 1;
	while (e > 0) {
		if (e % 2 == 1) {
			y = y * x % mod;
		}
		x = x * x % mod;
		e /= 2;
	}
	return y;
}

void solve() {
	int n, m, v;
	cin >> n >> m >> v;
	vector<int> c(m), d(m);
	bool ok = true;
	for (int i = 0; i < m; ++i) {
		cin >> c[i] >> d[i];
		if (c[i] != i) ok = false;
	}
	if (m == n && ok) {
		int ans = ((power(1LL * v * v % mod, n - 1) - (n - 1LL) * (v - 1LL)) % mod + mod) % mod;
		cout << ans << '\n';
	}
}

int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T;
	cin >> T;
	while (0 && T--) solve();
}
