#include <algorithm>
#include <cstdio>
#include <iostream>
#define int long long
using namespace std;
typedef pair <int, int> PII;
const int N = 1e5 + 5, P = 1e9 + 7;
int t, n, m, v, pos[N], dp[N][2];PII opt[N];

int qpow(int a, int b)
{
	int res = 1;
	while(b)
	{
		if(b & 1)res = 1ll * res * a % P;
		a = 1ll * a * a % P;
		b >>= 1;
	}
	return res;
}

signed main()
{
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	scanf("%lld", &t);
	while(t--)
	{
		bool flag = true;
		scanf("%lld%lld%lld", &n, &m, &v);
		for(int i = 1;i <= m;i++)scanf("%lld%lld", &opt[i].first, &opt[i].second);
		sort(opt + 1, opt + m + 1), m = unique(opt + 1, opt + m + 1) - opt - 1;
		for(int i = 2;i <= m;i++)
			if(opt[i].first == opt[i - 1].first)
				{
					puts("0"), flag = false;
					break;
				}
		if(!flag)continue;
		for(int i = 1;i <= m;i++)pos[i] = opt[i].first;
		if(pos[m] != n)
			dp[m][0] = 1ll * (v - 1) * v % P * qpow(1ll * v * v % P, n - pos[m] - 1) % P,
			dp[m][1] = 1ll * v * qpow(1ll * v * v % P, n - pos[m] - 1) % P;
		else dp[m][0] = 0, dp[m][1] = 1;
		for(int i = m - 1;i >= 1;i--)
		{
			int sum = (dp[i + 1][0] + dp[i + 1][1]) % P;
			dp[i][0] = 1ll * (v - 1) * v % P * qpow(1ll * v * v % P, pos[i + 1] - pos[i] - 1) % P * sum % P;
			dp[i][1] = 1ll * v * qpow(1ll * v * v % P, pos[i + 1] - pos[i] - 1) % P * sum % P;
			dp[i][1] = (dp[i][1] - 1ll * ((qpow(v, pos[i + 1] - pos[i]) - qpow(v, pos[i + 1] - pos[i] - 1) + P) % P) * sum % P + P) % P;
		}
		int ans = 1ll * qpow(1ll * v * v % P, pos[1] - 1) * ((dp[1][0] + dp[1][1]) % P) % P;
		printf("%lld\n", ans);
	}
	return 0;
}
