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

const int MXM = 1e5;
const int MOD = 1e9 + 7;

int t, n, m, v;
struct node{
	int c, d;
}a[MXM];
long long ns;
vector< node > b;
bool ok;

bool cmp(node x, node y){
	return x.c != y.c ? x.c < y.c : x.d < y.d;
}

long long qpow(long long x, int k){
	long long res = 1;
	for(;k;(x *= x) %= MOD, k >>= 1)
		if(k & 1) (res *= x) %= MOD;
	return res;
}

int main(){
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int i;
	for(scanf("%d", &t);t;--t){
		scanf("%d%d%d", &n, &m, &v);
		for(i = 0;i < m;++i) scanf("%d%d", &a[i].c, &a[i].d);
		sort(a, a + m, cmp);
		ok = 0;
		for(i = 1;i < m;++i)
			if(a[i].c == a[i - 1].c && a[i].d != a[i - 1].d){
				ok = 1;
				break;
			}
		if(ok){
			puts("0");
			continue;
		}
		b.clear();
		b.push_back(a[0]);
		for(i = 1;i < m;++i)
			if(b.back().c != a[i].c) b.push_back(a[i]);
		ns = 1;
		for(i = 1;i < b.size();++i){
			long long res = qpow(v, b[i].c - b[i - 1].c << 1) - qpow(v, b[i].c - b[i - 1].c - 1) * (v - 1);
			res = (res % MOD + MOD) % MOD;
			(ns *= res) %= MOD;
		}
		printf("%lld\n", ns * qpow(v, b[0].c - 1 << 1) % MOD * qpow(v, n - b.back().c << 1) % MOD);
	}
	return 0;
}
