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

const int mod = 1000000007;

struct num{
	int id, w;
}val[100010];

int n, m, v;

bool cmp(num z, num x){
	return z.id < x.id;
}

int get(int z, int x){
	int z1 = z % mod, sum = 1;
	while(x > 0){
		if(x % 2 == 1)
			sum = sum * z1 % mod;
		z1 = z1 * z1 % mod, x /= 2; 
	}
	return sum;
}

void solve(){
	cin >> n >> m >> v;
	for(int i = 1; i <= m; i++)
		cin >> val[i].id >> val[i].w;
	sort(val + 1, val + m + 1, cmp);
	int ans = get(v, (val[1].id - 1) * 2), pre = val[1].id;
	for(int i = 2; i <= m; i++){
		if(val[i].id == pre){
			if(val[i].w != val[i - 1].w){
				cout << 0 << '\n';
				return ;
			}
		}
		else{
			ans = ans * ((get(v, (val[i].id - pre) * 2) - get(v, val[i].id - pre - 1) * (v - 1) % mod + mod) % mod) % mod;
		}
		pre = val[i].id;
	}
	ans = ans * get(v, (n - pre) * 2) % mod;
	cout << ans << '\n';
}

signed main(){
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	int t;
	cin >> t;
	for(int i = 1; i <= t; i++)
		solve();
	return 0;
}
