#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long T , n , m , v;
struct node {
	long long c , d;
} a[100010];
bool cmp (node a , node b) {
	return a.c < b.c;
}
long long f (long long x , long long y) {
	long long sum = 1;
	while ( y ) {
		if (y & 1) sum = (sum * x) % MOD;
		x = (x * x) % MOD;
		y >>= 1;
	} 
	return sum;
}
long long ans;
int main () {
	freopen ("assign.in" , "r" , stdin);
	freopen ("assign.out" , "w" , stdout);
	cin >> T;
	while (T --) {
		cin >> n >> m >> v; ans = 1;
		for (int i = 1;i <= m;i ++) {
			cin >> a[i].c >> a[i].d;
		}
		sort (a + 1 , a + m + 1 , cmp);
		for (int i = 1;i < m;i ++) {
			long long k = a[i + 1].c - a[i].c;
			if ( !k ) {
				if (a[i + 1].d != a[i].d) {
					ans = 0;
					break;
				}
				continue;
			}
			ans = ans * (((f (v , 2 * k) - f (v , k - 1) * (v - 1)) % MOD + MOD) % MOD) % MOD;
		}
		ans = ans * f (v , 2 * (a[1].c - 1)) % MOD;
		ans = ans * f (v , 2 * (n - a[m].c)) % MOD;
		cout << (ans % MOD + MOD) % MOD << '\n';
	}
	
	return 0;
}





