#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int N = 1e5 + 10;
const ll P = 1e9 + 7;
int T, n, d, r, m;
ll v, ans;
bool f;
struct node
{
	int i;
	ll x;
	bool operator < (const node &a)
	{
		return i < a.i;
	}
} c[N];
ll qpow(ll a, ll b)
{
	ll q = 1, k = a % P;
	while(b > 0)
	{
		if(b & 1) q = q * k % P;
		k = k * k % P;
		b >>= 1;
	}
	return q;
}
int main()
{
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	cin.tie(0), cout.tie(0);
	ios::sync_with_stdio(0);
	cin >> T;
	while(T--)
	{
		ans = 1, d = r = 0;
		f = false;
		cin >> n >> m >> v;
		for(int i = 1; i <= m; i++)
		{
			cin >> c[i].i >> c[i].x;
		}
		sort(c + 1, c + m + 1);
		for(int i = 1; i <= m; i++)
		{
			r = max(c[i].i, r);
			if(c[i].i == c[i - 1].i)
			{
				if(c[i].x != c[i - 1].x)
				{
					f = true;
					break;
				}
			}
		}
		if(f)
		{
			cout << "0\n";
			continue;
		}
		ans = qpow(v * v % P, n - r);
		for(int i = m; i >= 1; i--)
		{
			if(c[i].i == r) continue;
			ans = ((qpow(v * v % P, r - c[i].i) * v % P * (v - 1) % P
			  - (v - 1) * v % P) % P + P) % P * qpow((v * v % P - 1 + P) % P, P - 2) % P;
			r = c[i].i;
		}
		ans = ans * qpow(v * v % P, r - 1) % P;
		cout << ans << "\n";
	}
	return 0;
}
