#include<bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
#define ll long long
#define vc vector
#define vci vc<int>
#define psb push_back
using namespace std;
ll md;
inline ll ksm(ll a, ll b, ll md){
	a %= md;
	ll ans = 1;
	while(b){
		if(b & 1) ans = ans * a % md;
		a = a * a % md;
		b >>= 1;
	}
	return ans;
}
inline ll read(){
	ll ans = 0;
	bool fl = 0;
	char c;
	while(1){
		c = getchar();
		if(c == '-' || ('0' <= c && c <= '9')) break;
	}
	if(c == '-') fl = 1;
	else ans = (int)(c - '0');
	while(1){
		c = getchar();
		if(c < '0' || c > '9') break;
		ans = (ans << 3) + (ans << 1);
		ans += (int)(c - '0');
	}
	if(fl) ans = ans * -1;
	return ans;
}
int n, m, v, t, fl, id[200005], tot, sq = 100000;
ll cf1[200005], cf2[200005];//ΉβΛΩΓέ 
ll ans;
pii a[200005];
void init(){
	for(int i = 1; i <= m; i++) id[i] = 0;
	ans = fl = 1;
	tot = 0;
	cf1[0] = 1;
	for(int i = 1; i <= sq; i++) cf1[i] = cf1[i - 1] * v % md;
	cf2[0] = 1;
	for(int i = 1; i <= sq; i++) cf2[i] = cf2[i - 1] * cf1[sq] % md;
}
ll get(ll x){
	return cf2[x / sq] * cf1[x % sq] % md;
}
int main(){
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	md = 1e9 + 7;
	cin >> t;
	while(t--){
		cin >> n >> m >> v;
		init();
		for(int i = 1, x, y; i <= m; i++){
			scanf("%d%d", &x, &y);
			a[i] = ((pii){x, y});
//			if(!is[a]){
//				is[a] = b;
//				id[++tot] = i;
//			}
//			else fl &= (is[a] == b);
		}
		sort(a + 1, a + m + 1);
		for(int i = 1; i <= m; i++){
			if(i == 1){
				id[++tot] = a[i].F;
				continue;
			}
			if(a[i].F != a[i - 1].F) id[++tot] = a[i].F;
			else fl &= (a[i].S == a[i - 1].S);
		}
		if(!fl){
			cout << 0 << endl;
			continue;
		}
		m = tot;
//		cout << m << ' ' << id[1] << ' ';
		ans = get(2 * (id[1] - 1));
//		cout << ans << endl;
		for(int i = 1; i < m; i++){
			ans = ans * ((get(2 * (id[i + 1] - id[i])) - get(id[i + 1] - id[i] - 1) * (v - 1)) % md + md) % md;
//			ans = ans * (ksm(n * n % md, id[i + 1] - id[i], md) - ksm(n, id[i + 1] - id[i] - 1) *  + md) % md;
		}
		ans = ans * get(2 * (n - id[m])) % md;
		cout << ans << endl;
	}
	return 0;
}
