#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007ll;
int T,n,m,v,cnt;
long long ans;
pair<int,int>lmt[100001];
inline int read(){
	int num = 0;
	char c = getchar();
	while(c < '0' || c > '9') c = getchar();
	while(c >= '0' && c <= '9') num = num * 10 + c - '0',c = getchar();
	return num;
}
long long qp(long long a,long long b){
	if(!b) return 1ll;
	long long c = qp(a,b >> 1);
	c = c * c % MOD; 
	if(b & 1) c = c * a % MOD;
	return c;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	T = read();
	while(T --){
		ans = 1ll;
		n = read(),m = read(),v = read();
		cnt = m;
		for(int i = 1;i <= m;i ++){
			lmt[i].first = read(),lmt[i].second = read();
		}
		sort(lmt + 1,lmt + m + 1);
		ans = qp((long long)v,2 * (lmt[1].first - 1));
		for(int i = 1;i < m;i ++){
			if(lmt[i].first == lmt[i + 1].first){
				if(lmt[i].second == lmt[i + 1].second){
					continue;
				}
				ans = 0ll;
			}
			else{
				int x = lmt[i].first,y = lmt[i + 1].first;
				ans = ans * ((qp((long long)v,2 * (y - x)) - qp((long long)v,y - x - 1) * (v - 1) % MOD + MOD) % MOD) % MOD;
			}
		}
		ans = ans * qp((long long)v,2 * (n - lmt[m].first)) % MOD;
		printf("%lld\n",ans);
	}
	return 0;
}
//10:01 finish
