#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int T, n, m, v;
struct node{
	int c, d;
} s[100005];
int quickpow(int a, int b){
	int res = 1;
	while(b){
		if(b&1) res = res*a%mod;
		a = a*a%mod;
		b >>= 1;
	} return res;
}
signed main(){
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> T;
	while(T--){
		cin >> n >> m >> v;
		for(int i = 1; i <= m; i++) cin >> s[i].c >> s[i].d;
		sort(s+1, s+1+m, [](node pre, node nxt){ return pre.c < nxt.c; });
		int now = 1, no = 0, res = 1;
		s[0].c = 1; bool flg = 1;
		for(int i = 1; i <= m; i++){
			if(i > 1 && s[i].c == s[i-1].c && s[i].d != s[i-1].d){
				flg = 0;
				break;
			}
			if(s[i].c == s[i-1].c && s[i].d == s[i-1].d) continue;
			if(i == 1){
				if(s[i].c != 1) res = res*quickpow(v, 2*(s[i].c-1))%mod;
			}
			else{
				res = res*(quickpow(v, 2*(s[i].c-s[i-1].c))%mod-quickpow(v, s[i].c-s[i-1].c-1)*(v-1)%mod)%mod;
			}
		} res = res*quickpow(v, 2*(n-s[m].c))%mod;
		if(flg) cout << (res%mod+mod)%mod << endl;
		else cout << 0 << endl;
	}
	return 0;
}
