#include <algorithm>
#include <iostream>
using namespace std;

#define MAXN 100005
#define MOD 1000000007ll

using ll = long long;

ll qpow(ll b, ll p, ll m)
{
	ll r = 1;
	while (p)
	{
		if (p & 1)
		{
			r = r * b % m;
		}
		b = b * b % m;
		p >>= 1;
	}
	return r;
}

struct Query
{
	int c;
	ll d;
} q[MAXN];

bool cmp(Query a, Query b)
{
	return a.c < b.c;
}

ll n, m, v;

void solve()
{
	cin >> n >> m >> v;
	for (int i = 1; i <= m; i++)
	{
		cin >> q[i].c >> q[i].d;
	}
	sort(q + 1, q + m + 1, cmp);
	ll res = 1;
	if (q[1].c > 1)
	{
		(res *= qpow(v, 2 * (q[1].c - 1), MOD)) %= MOD;
	}
	for (int i = 1; i < m; i++)
	{
		if (q[i].c == q[i + 1].c)
		{
			if (q[i].d == q[i + 1].d)
			{
				continue;
			}
			cout << 0 << endl;
			return;
		}
		int cn = q[i + 1].c - q[i].c - 1;
		(res *= (qpow(v, 2 * cn + 2, MOD) + MOD - qpow(v, cn + 1, MOD) + qpow(v, cn, MOD)) % MOD) %= MOD;
	}
	if (q[m].c < n)
	{
		(res *= qpow(v, 2 * (n - q[m].c), MOD)) %= MOD;
	}
	cout << res << endl;
}

int main()
{
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

