#include <bits/stdc++.h>
#define Code using
#define by namespace
#define zzx std
#define mod 1000000007
Code by zzx;
int T;
long long n, m, v, ans;
pair<long long, long long> a[100010];
long long q_pow(long long x, long long y)
{
	long long res = 1;
	x %= mod;
	while(y > 0)
	{
		if(y % 2 == 1)
		{
			res = res * x % mod;
		}
		x = x * x % mod;
		y /= 2;
	}
	return res;
}
bool cmp(pair<long long, long long> x, pair<long long, long long> y)
{
	return x.first< y.first;
}
int main()
{
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	scanf("%d", &T);
	while(T--)
	{
		scanf("%lld %lld %lld", &n, &m, &v);
		for(long long i = 1; i <= m; ++i)
		{
			scanf("%lld %lld", &a[i].first, &a[i].second);
		}
		int flag = 0;
		sort(a + 1, a + m + 1);
		for(long long i = 1; i <= m; ++i)
		{
			if(a[i].first == a[i - 1].first && a[i].second != a[i - 1].second)
			{
				printf("0\n");
				flag = 1;
				break;
			}
		}
		if(flag == 1)
		{
			continue;
		}
		ans = q_pow(v, 2 * (a[1].first - 1));
		for(long long i = 2; i <= m; ++i)
		{
			if(a[i].first == a[i - 1].first)
			{
				continue;
			}
			long long k = a[i].first - a[i - 1].first;
			ans = ans * ((q_pow(v, 2 * k) - q_pow(v, k - 1) * (v - 1) % mod + mod) % mod) % mod;
		}
		ans = ans * q_pow(v, 2 * (n - a[m].first)) % mod;
		printf("%lld\n", ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
//9:35 get idea(why so ez)
//9:54 finish code
//10:01 finish debug
