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

#define ofor(i, a, b) for (int i = a; i < b; i++)
#define cfor(i, a, b) for (int i = a; i <= b; i++)
#define bfor(i, a, b) for (int i = a; i >= b; i--)
#define mset(a, x) memset(a, x, sizeof(a))

const int X = 1e5 + 5;
const int mod = 1e9 + 7;

int T, n, m;
ll v, ans;
struct num {
	int pos;
	ll val;
} a[X];
int cnt;
map<int, ll> mp;

bool cmp(num x, num y) {
	return x.pos < y.pos;
}

void INIT() {
	mp.clear();
	cnt = 0;
	ans = 1;
	return;
}

bool Input() {
	cfor (i, 1, m) {
		int pos;
		ll val;
		cin >> pos >> val;
		if (mp.count(pos)) {
			if (mp[pos] != val) return false;
			else continue;
		}
		mp[pos] = val;
		a[++cnt] = {pos, val};
	}
	return true;
}

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

int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> T;
	while (T--) {
		INIT();
		cin >> n >> m >> v;
		if (not Input()) {
			cout << 0 << endl;
			continue;
		}
		
		sort(a+1, a+cnt+1, cmp);
		
		ans *= qpow(v, 2 * (a[1].pos - 1));
		ans %= mod;
		
		
		cfor (i, 2, cnt) {
			ll tmp = qpow(v, 2 * (a[i].pos - a[i-1].pos));
			tmp -= qpow(v, a[i].pos - a[i-1].pos - 1) * (v - 1) % mod;
			while (tmp < 0) tmp += mod;
			ans *= tmp;
			ans %= mod;
		}
		
		ans *= qpow(v, 2 * (n - a[cnt].pos));
		ans %= mod;
		
		cout << ans << endl;
	}
	
	return 0;
}
