#include <bits/stdc++.h>
using namespace std;
const int M = 100240, P = 1000000007;
struct node
{
	int c, d;
	node() {}
	node(int C, int D) : c(C), d(D) {}
	inline bool operator<(node x) const
	{
		return c == x.c ? d < x.d : c < x.c;
	}
	inline bool operator==(node x) const
	{
		return c == x.c && d == x.d;
	}
} a[M];
//int f[N];
//bitset<N> b;
inline int Pow(int a, int b)
{
	int s = 1;
	for (; b != 0; b >>= 1, a = 1ll * a * a % P)
		if ((b & 1) == 1)
			s = 1ll * s * a % P;
	return s;
}
inline int Inv(int x)
{
	return Pow(x, P - 2);
}
inline void Solve()
{
	int n, m, v;
	cin >> n >> m >> v;
	for (int i = 1; i <= m; ++i)
		cin >> a[i].c >> a[i].d;
	sort(a + 1, a + m + 1);
	for (int i = 1; i <= m; ++i)
	{
		if (a[i].c == a[i - 1].c && a[i].d != a[i - 1].d)
		{
			cout << "0\n";
			return;
		}
	}
	m = unique(a + 1, a + m + 1) - a - 1;
	int s = Pow(v, n * 2 - 2);
	for (int i = 2; i <= m; ++i)
	{
		if (a[i].c - 1 == a[i - 1].c)
			s = 1ll * s * Inv(1ll * v * v % P) % P * (1ll * v * (v - 1) % P + 1) % P;
		else
		{
			int l = a[i].c - a[i - 1].c + 1;
			s = 1ll * s * Inv(Pow(v, l * 2 - 2)) % P * ((Pow(v, l * 2 - 2) - 1ll * Pow(v, l - 2) * (v - 1) % P + P) % P) % P;
		}
	}
	cout << s << '\n';
}
int main()
{
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin >> t;
	while (t-- != 0)
		Solve();
	return 0;
}
