#include <bits/stdc++.h>

using namespace std;
const long long mod = 1000000007;
int T;
int n, m;
long long v;

void solve()
{
	scanf("%d%d%lld", &n, &m, &v);
	vector<long long> x(n+1, 0);
	int zero = 0;
	for(int i=1;i<=m;i++)
	{
		int c;
		long long d;
		scanf("%d%lld", &c, &d);
		if(x[c] != 0 && d != x[c]) zero = 1;
		x[c] = d;
	}
	if(zero)
	{
		printf("0\n");
		return;
	}
	long long ans = 1;
	for(int i=1;i<=n;i++)
	{
		long long c = 1;
		if(x[i] != 0)
		{
			if(i == n) c = 1;
			if(i != n)
			{
				if(x[i+1] == 0) c = v % mod * v%mod; //
				if(x[i+1] != 0) c = (v % mod * v%mod)%mod - ((v-1)%mod);
			}
			c%=mod;
		}
		if(x[i] == 0)
		{
			c = v%mod;
			if(i == n) c=1;
			if(i != n)
			{
				if(x[i+1] == 0) c = v%mod * v%mod;
				if(x[i+1] != 0) c = (2*v)%mod;
			}
			c%=mod;
		}
		ans = (ans%mod * c%mod) % mod;
	}
	printf("%lld\n", (ans+mod)%mod);
}

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

