#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int N = 1e5 + 10;

int T, n, m, k, v;
map <int, int> p; 
const int mod = 1e9 + 7;

struct node
{
	int l, r;
};

node a[N];

int fpow(int a, int b)
{
	int u = a % mod, t = b, ret = 1;
	while(t)
	{
		if(t & 1) ret = (ret * u) % mod;
		u = (u * u) % mod;
		t >>= 1; 
	}
	return ret;
}

void solve()
{
	cin >> n >> m >> v;
	p.clear(); 
	bool ok = 1;
	for(int i = 1;i <= m;i++)
	{
		int _c, _d;
		cin >> _c >> _d;
		if(p.count(_c) && p[_c] != _d) ok = 0; 
		p[_c] = _d;
	}
	if(!ok)
	{
		cout << 0 << endl;
		return;
	}
	k = 0;
	int l = -1, r = -1;
	for(auto it : p)
	{
		if(l == -1) l = r = it.first; 
		else
		{
			if(it.first == r + 1) r++;
			else
			{
				a[++k].l = l;
				a[k].r = r;
				l = r = it.first;
			}
		} 
	}
	a[++k].l = l;
	a[k].r = r;
	int ans = 1, lst = 1;
	for(int i = 1;i <= k;i++)
	{
		int l = a[i].l, r = a[i].r;
		ans = (ans * fpow(v * v % mod, max(0ll, l - 1 - lst))) % mod;
		if(l > 1) ans = (ans * ((v * (v - 1) % mod + v % mod) % mod)) % mod;
		ans = (ans * fpow((1 + v * (v - 1) % mod) % mod, r - l)) % mod;
		if(r < n) ans = (ans * ((v * (v - 1) % mod + v % mod) % mod)) % mod;
		lst = r + 1;
	}
	if(lst < n) ans = (ans * fpow(v * v % mod, n - lst)) % mod;
	cout << ans << endl;
} 

signed main()
{
	#ifndef SCZ
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> T;
	while(T--) solve();
	return 0;
}
