#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 2e5;
const long long mod = 1e9 + 7;
int n, m, v;
int s[MAXN];
bool b[MAXN];
long long dfs(int x, int lock)
{
	if(lock && s[x] != -1) //不合规矩
		return 0;
	if(x == n)
		return 1;
	long long res = 0;
	if(!lock && s[x] == -1)
	{
		//根本没被锁
		(res += dfs(x + 1, 0) % mod * v % mod * v % mod) %= mod;
	}
	else
	{
		//有限制
		if(b[x + 1]) //如果下一个被锁了
			(res += dfs(x + 1, 0)) %= mod;
		else
			(res += dfs(x + 1, 1) * v % mod) %= mod;
		(res += dfs(x + 1, 0) * v % mod * (v - 1) % mod) %= mod;
	}
	return res;
}
void solve()
{
	scanf("%d%d%d", &n, &m, &v);
	for(int i = 1; i <= n; i++)
		s[i] = -1, b[i] = 0;
	bool flag = false;
	for(int i = 1; i <= m; i++)
	{
		int c, d;
		scanf("%d%d", &c, &d);
		if(b[c] && s[c] != d)
			flag = true;
		s[c] = d;
		b[c] = 1;//这个值是固定的
	}
	if(flag)
		printf("0\n");
	else
		printf("%lld\n", dfs(1, 0));
}


int main()
{
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int T;
	scanf("%d", &T);
	while(T--)
		solve();
}
