#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct node{
	ll c ,d;
	
	node()
	{
		c = d = 0;
	}
};
const int mod = 1e9 + 7;
const int M = 1e5 + 10;
ll dp[M];
node a[M];

ll qpow(ll a ,ll b)
{
	ll ret = 1;
	while (b)
	{
		if (b & 1)
			ret = ret * a % mod;
		a = a * a % mod;
		b >>= 1; 
	}
	return ret;
}

bool cmp(node a ,node b)
{
	return a.c == b.c ? a.d < b.d : a.c < b.c;
}

void solve()
{
	memset(dp ,0 ,sizeof(dp));
	for (int i = 0;i < M;i++)
		a[i].c = a[i].d = 0;
	ll n ,m ,v;
	scanf("%lld%lld%lld",&n ,&m ,&v);
	
	for (int i = 1;i <= m;i++)
		scanf("%lld%lld",&a[i].c ,&a[i].d);
	
	sort(a + 1 ,a + 1 + m ,cmp);
	
	dp[1] = qpow(v * v % mod ,a[1].c - 1);
	for (int i = 2;i <= m;i++)
	{
		if (a[i].c == a[i - 1].c)
		{
			if (a[i].d != a[i - 1].d)
			{
				printf("0\n");
				return ;
			}
			dp[i] = dp[i - 1];
			continue; 
		}
		dp[i] = dp[i - 1] * (qpow(v * v % mod ,a[i].c - a[i - 1].c) - qpow(v ,a[i].c - a[i - 1].c - 1) * (v - 1) % mod + mod) % mod;
	}
	
	printf("%lld\n",dp[m] * qpow(v * v % mod ,n - a[m].c) % mod);
}

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