#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100005, mod = 1000000007;
int T, n, m, v;
struct S{ int x, d;} a[N];
int qpow(int x, int y){
	int ans = 1;
	for(; y; y >>= 1) ans = y & 1? ans * x % mod: ans, x = x * x % mod;
	return ans;
}
signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	cin >> T;
	while(T--){
		cin >> n >> m >> v;
		int fl = 0;
		for(int i = 1; i <= m; i++) cin >> a[i].x >> a[i].d;
		sort(a + 1, a + m + 1, [](S x, S y){ return x.x != y.x? x.x < y.x: x.d < y.d;});
		for(int i = 2; i <= m; i++)
			if(a[i].x == a[i - 1].x && a[i].d != a[i - 1].d) fl = 1;
		if(fl){ cout << "0\n"; continue;}
		int ans = qpow(v * v % mod, a[1].x - 1);
		for(int i = 2; i <= m; i++) if(a[i].x != a[i - 1].x) 
			ans = ans * (qpow(v * v % mod, a[i].x - a[i - 1].x) - qpow(v, a[i].x - a[i - 1].x - 1) % mod * (v - 1) % mod + mod) % mod;
		ans = ans * qpow(v * v % mod, n - a[m].x) % mod;
		cout << ans << '\n';
	}
	return 0;
}
