#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
const int M = 1e5 + 7;
const ll mod = 1e9 + 7;
ll T,n,m,v;
struct lim{
	ll c,d;
}li[M]; 
ll fpow(ll a,ll b) {
	ll res = 1;
	while(b) {
		if(b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
int main() {
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);	
	ios::sync_with_stdio(0);
	cin>>T;
	while(T--) {
		cin>>n>>m>>v;
		for(int i=1;i<=m;++i) cin>>li[i].c>>li[i].d;
		sort(li+1,li+m+1,[](const lim &a,const lim &b){
			return a.c < b.c;
		});
		bool flag_end = 0;
		for(int i=1;i<m;++i) if(li[i].c == li[i+1].c && li[i].d != li[i+1].d) {
			flag_end = 1;
			cout<<0<<endl;
			break;
		}
		if(flag_end == 1) continue;
		ll ans = fpow(v*v%mod,(li[1].c-1 + n - li[m].c + mod) % mod);
		for(int i=1;i<m;++i) {
			if(li[i].c == li[i+1].c) continue;
			ans *= (fpow(v*v%mod,li[i+1].c-li[i].c) - fpow(v,li[i+1].c-li[i].c-1)*(v-1)%mod + mod)%mod;
			ans %= mod;
		} 
		cout<<ans<<endl;
	}
	return 0;
}
/*
1
557584238 1 464289274
309302662 462600170
*/
