#include <bits/stdc++.H>
using namespace std;

const int N = 1e5 + 10, mod = 1e9 + 7;
int t, n, m;
long long v, V;
bool flag;
pair<int, int> a[N];
long long f[N];

long long qpow(long long a, int k)
{
	long long res = 1;
	while (k)
	{
		if (k & 1) res = res * a % mod;
		a = a * a % mod, k >>= 1;
	}
	return res;
}

int main()
{
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
//	freopen("assign3.in", "r", stdin);
//	freopen("assign.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> t;
	while (t--)
	{
		cin >> n >> m >> v, V = v * v % mod;
		for (int i = 1, d; i <= m; ++i) cin >> a[i].first >> a[i].second;
		sort(a + 1, a + m + 1);
		flag = 0;
		for (int i = 2; i <= m; ++i)
			if (a[i].first == a[i - 1].first && a[i].second != a[i - 1].second)
			{
				flag = 1;
				break;
			}
		if (flag) { cout << "0\n"; continue; }
		if (a[1].first == 1) f[1] = 1;
		else f[1] = qpow(V, a[1].first - 1) % mod;
		for (int i = 2; i <= m; ++i)
		{
			if (a[i].first == a[i - 1].first) f[i] = f[i - 1];
			else if (a[i].first == a[i - 1].first + 1) f[i] = f[i - 1] * ((v - 1) * v % mod + 1) % mod;
			else f[i] = f[i - 1] * qpow(V, a[i].first - a[i - 1].first - 1) % mod * (V - v + 1) % mod;
			if (f[i] < 0) f[i] += mod;
		}
		//	else if (a[i].first == a[i - 1].first + 2) f[i] = f[i - 1] * V % mod * (V - v + 1) % mod;
//		for (int i = 1; i <= m; ++i) cout << a[i].first << ' ' << f[i] << '\n';
//		cout << '\n';
		if (a[m].first == n) cout << f[m] << '\n';
		else cout << f[m] * qpow(V, n - a[m].first - 1) % mod * (V - v + 1) % mod << '\n';
	}
	return 0;
}
/*
1
10 11 2
10 2
7 2
7 2
2 2
3 2
4 2
10 2
7 2
10 2
3 2
3 2
*/
