#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10, mod = 1e9 + 7;
long long n, m, v;
struct node{
	long long c, d;
}a[N];
bool cmp(node xx, node yy){
	return xx.c < yy.c;
}
long long f[N][2];
long long qp(long long x, long long y){
	long long res = 1;
	while(y){
		if(y & 1) res = res * x % mod;
		y >>= 1, x = x * x % mod;
	}
	return res;
}
void solve(){
	scanf("%lld%lld%lld", &n, &m, &v);
//	printf("#n = %lld m = %lld v = %lld\n", n, m, v);
	for(int i = 1; i <= m; i++) scanf("%lld%lld", &a[i].c, &a[i].d);
	sort(a + 1, a + m + 1, cmp);
//	return;
	memset(f, 0, sizeof(f));
	f[1][0] = qp(v, 2*(a[1].c-1));
	for(int i  = 2; i <= m; i++){
//		printf("i = %d\n", i);
		if(a[i].c == a[i-1].c){
			if(a[i].d != a[i-1].d){
				puts("0");
				return;
			}
			f[i][0] = f[i-1][0], f[i][1] = f[i-1][1];
			continue;
		}
		long long temp = qp(v, a[i].c - a[i-1].c-1) * (v-1) % mod;
		f[i][0] = f[i-1][0] * (qp(v, 2*(a[i].c-a[i-1].c)) - temp) % mod;
		f[i][1] = f[i-1][1] * qp(v, 2*(a[i].c-a[i-1].c)) % mod + f[i-1][0] * temp % mod;
	}
	long long ans = qp(v, 2*(n-1)) - f[m][1] * qp(v, 2*(n-a[m].c));
	printf("%lld\n", ((ans % mod) + mod) % mod);
}
int main(){
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int T; scanf("%d", &T);
	while(T--) solve();
	return 0;
}
