#include <bits/stdc++.h> 

using namespace std;
typedef long long ll;
const int M = 1e5 + 5, MOD = 1e9 + 7;

inline ll read() {
	int flg = 1;
	ll ret = 0;
	char ch;
	ch = getchar();
	while (!('0' <= ch && ch <= '9') && !(ch == '-'))
		ch = getchar();
	if (ch == '-') {
		flg = -1;
		ch = getchar();
	}
	do {
		ret = ret * 10 + ch - '0';
		ch = getchar();
	} while ('0' <= ch && ch <= '9');
	return ret;
}

ll n, m, v; //变量个数，确定个数，值域
//x[c[i]] = d[i]
pair<ll, ll> p[M];
int cur = 0;
pair<ll, ll> tp[M];

ll fpow(ll a, ll b, ll p) {
	ll mul = 1;
	while (b) {
		if (b & 1)
			mul = mul * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return mul;
}

ll ans;
void slv() {
	scanf("%lld%lld%lld", &n, &m, &v);
	for (int i = 1; i <= m; i++) {
		p[i].first = read();
		p[i].second = read();
	}
	sort(p + 1, p + m + 1);
	for (int i = 1; i < m; i++)
		if (p[i].first == p[i + 1].first && p[i].second != p[i + 1].second) {
			puts("0");
			return ;
		}
	cur = 0;
	for (int i = 1; i <= m; i++) {
		if (i == 1 || p[i].first != p[i - 1].first) {
			tp[++cur] = p[i];
		}
	}
	for (int i = 1; i <= cur; i++)
		p[i] = tp[i];
	m = cur;
	
	ans = 1;
	ans = fpow(v, 2 * (p[1].first - 1), MOD); //开头 
	ans = ans * fpow(v, 2 * (n - p[m].first), MOD) % MOD; //结尾 
	
	for (int i = 1; i < m; i++) { //处理限制 p[i]与p[i+1] 
		ll tmp = fpow(v, 2 * (p[i + 1].first - p[i].first), MOD);
		tmp = tmp - (v - 1) * fpow(v, p[i + 1].first - p[i].first - 1, MOD) % MOD;
		tmp = (tmp % MOD + MOD) % MOD;
		ans = ans * tmp % MOD;
	}
	printf("%lld\n", ans);
}

int main() {
//	freopen("1.in", "r", stdin);
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int T;
	cin >> T;
	while (T--)
		slv();
	return 0;
}
