#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define LLL __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mkp make_pair
using namespace std;

int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return s * f;
}

template <typename T>
void chkmn(T &x, T y) { x = x < y ? x : y;}
template <typename T>
void chkmx(T &x, T y) { x = y < x ? x : y;}

const int mod = 1e9 + 7;

int qpow(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;
}

auto fplus = [](int x, int y) {return x + y < mod ? x + y : x + y - mod;};
auto fminus = [](int x, int y) {return x >= y ? x - y : x + mod - y;};
auto Fplus = [](int &x, int y) {x = fplus(x, y);};
auto Fminus = [](int &x, int &y) {x = fminus(x, y);};

const int MAXN = 100005;

int n, m, v;
pii a[MAXN];

int calc(int n) { return fminus(qpow(1ll * v * v % mod, n - 1), 1ll * qpow(v, n - 2) * (v - 1) % mod);}

int work() {
	n = read(), m = read(), v = read();
	for (int i = 1; i <= m; i++)
		a[i].fi = read(), a[i].se = read();
	sort(a + 1, a + m + 1);
	m = unique(a + 1, a + m + 1) - a - 1;
	for (int i = 1; i < m; i++)
		if (a[i].fi == a[i + 1].fi) return 0;
	int ans = qpow(1ll * v * v % mod, a[1].fi - 1 + n - a[m].fi);
	for (int i = 1; i < m; i++) ans = 1ll * ans * calc(a[i + 1].fi - a[i].fi + 1) % mod;
	return ans;
}

int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int T = read();
	while (T--) printf("%d\n", work());
	return 0;
}
