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

#define ll long long
#define PII pair<int , int> 
#define lowbit(x) (x & -x)

bool ST;
const int N = 1e5 + 10;
const int Mod = 1e9 + 7;
const ll MOD = 1e9 + 7;
int n , T , m , v , V;
int dp[N] , a[N];ll ans;
struct gardenia{
	int c , d;
	bool operator < (const gardenia &a) const {
		return c < a.c;
	}
}g[N];

int read(){
	int sum = 0;
	bool flag = true;
	char c = getchar();
	for(;!isdigit(c);c = getchar())if(c == '-')flag ^= true;
	for(;isdigit(c);c = getchar())sum = (sum << 1) + (sum << 3) + (c ^ 48);
	return flag ? sum : -sum;
}
void out_write(int x){if(x > 9)out_write(x / 10);putchar(x % 10 + '0');}
void write(int x){if(x < 0){putchar('-');out_write(-x);}else out_write(x);}
ll qpow(int s , int n){
	ll res = 1;ll x = s;
	while(n){
		if(n & 1)res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res;
}
void work(){
	n = read();m = read();v = read();V = qpow(v , 2);
//	cerr << n << " " << m << " " << v << endl;
//	dfs(1)
	for(int i = 1;i <= m;++ i){
		g[i].c = read();g[i].d = read();
//		a[g[i].c] = g[i].d;
	}
	if(m == 1){
		write(qpow(V , n - 1) % MOD);putchar('\n');
		return;
	}
	sort(g + 1 , g + m + 1);
	ans = 1;
	for(int i = 1;i <= m;++ i){
		if(i > 1 && g[i].c == g[i - 1].c && g[i].d != g[i - 1].d){ans = 0;break;}
		if(i == 1 && g[i].c == 1)continue;
		else if(i == 1){
			ans = ans * qpow(V , g[i].c - 1) % MOD;
		}
		else {
			if(g[i].c == g[i - 1].c + 1){
//				cerr << T << endl;
				ans = ans * (V - v + 1) % MOD;
			}
			else ans = ans * qpow(V , g[i].c - g[i - 1].c) % MOD;
		}
	}
	write(ans);putchar('\n');
}
bool ED;

int main(){
	freopen("assign.in" , "r" , stdin);
	freopen("assign.out" , "w" , stdout);
//	cerr << ((&ST) - (&ED)) / 1024.0 / 1024.0 << endl;
//	double st = clock();
	T = read();
	while(T --){work();}
//	double ed = clock();
//	cerr << (ed - st) / CLOCKS_PER_SEC << endl;
	return 0;
}
/*

1
10 5 2
10 2
7 2
2 2
3 2
4 2
1 2 3 4 5 6 7 8 9 10
  2 2 2     2     2
 4 3 3 3 5 4 3 5 4

4 4 4 3 3 3 3 5 5
129600
*/
