#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MaxN = 2e5 + 5;
const LL Mod = 1e9 + 7;
LL Pow(LL A, LL K)
{
	LL Res = 1;
	while (K)
	{
		if (K & 1)
		{
			Res = Res * A % Mod;
		}
		A = A * A % Mod;
		K >>= 1;
	}
	return Res;
}
LL T, N, M, V;
struct Node
{
	LL Pos, Val;
	bool operator<(const Node& Mem) const
	{
		return Pos == Mem.Pos ? Val < Mem.Val : Pos < Mem.Pos;
	}
	bool operator==(const Node& Mem) const
	{
		return Pos == Mem.Pos && Val == Mem.Val;
	}
};
Node Arr[MaxN];
void Solve()
{
	scanf("%lld%lld%lld", &N, &M, &V);
	for (int i = 1; i <= M; ++i)
	{
		scanf("%lld%lld", &Arr[i].Pos, &Arr[i].Val);
	}
	sort(Arr + 1, Arr + 1 + M);
	M = unique(Arr + 1, Arr + 1 + M) - Arr - 1;
	for (int i = 1; i <= M; ++i)
	{
		if (Arr[i].Pos == Arr[i - 1].Pos && Arr[i].Val != Arr[i - 1].Val)
		{
			printf("0\n");
			return;
		}
	}
	LL Ans = Pow(V * V % Mod, Arr[1].Pos - 1);
	int Tot;
	for (int i = 2; i <= M; ++i)
	{
		Tot = Arr[i].Pos - Arr[i - 1].Pos;
		Ans = Ans * ((Pow(V * V % Mod, Tot) - Pow(V, Tot) + Pow(V, Tot - 1)) % Mod + Mod) % Mod;
	}
	Ans = Ans * Pow(V * V % Mod, N - Arr[M].Pos) % Mod;
	printf("%lld\n", Ans);
}
int main()
{
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	scanf("%lld", &T);
	while (T--)
	{
		Solve();
	}
	return 0;
}
