# include <bits/stdc++.h>
# define pb push_back
# define int long long
# define pii pair <int, int>
# define fi first
# define se second
using namespace std;

const int mod = 1e9 + 7;

int ksm(int x, int p){
	int ret = 1;
	while (p){
		if (p & 1) ret = ret * x % mod;
		x = x * x % mod;
		p >>= 1;
	}
	return ret;
}

int n, m, v;


void solve(){
	scanf("%lld%lld%lld", &n, &m, &v);
	vector <pii> vec;
	for (int i = 1;i <= m;i++){
		int c, d; scanf("%lld%lld", &c, &d);
		vec.pb({c, d});
	}
	sort (vec.begin(), vec.end());
	int ans = ksm(v*v%mod, n-1), V = v*v % mod;
	int sz = (int)vec.size(), xs = n-1, c = 1;
	for (int i = 0;i < sz-1;i++){
		if (vec[i].fi == vec[i+1].fi){
			if (vec[i].se != vec[i+1].se){
				puts("0");
				return ;
			}
			continue;
		}
		int A = vec[i].fi, B = vec[i+1].fi;
		xs -= (B - A);
		int tmp = ksm(v, B-A-1) % mod * (v-1) % mod;
		ans = (ans - ksm(V, xs) * c % mod * tmp + mod) % mod;
		(c *= (ksm(V, B-A) - tmp + mod) % mod) %= mod;
	}
	printf("%lld\n", (ans % mod + mod) % mod);
}

signed main(){
	freopen("assign.in",  "r", stdin);
	freopen("assign.out", "w", stdout);
//	freopen("assign1.in", "r", stdin);
//	freopen("my.txt", "w", stdout);
	int T; scanf("%lld", &T);
//	T = 
	while (T--) solve();	
	return 0;
}
