#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
struct P{
	int x,y;
}s[114514];

bool cmp(P a,P b){
	if (a.x == b.x){
		return a.y < b.y;
	}
	return a.x < b.x;
}

int fastpow(int a,int b){
	int ans = 1,sum = a;
	while (b){
		if (b & 1){
			ans = (ans * sum) % MOD;
		}
		sum = (sum * sum) % MOD;
		b >>= 1;
	}
	return ans;
}

void slove(){
	int n,m,v;
	cin>>n>>m>>v;
	for (int i = 1;i <= m;i++){
		cin>>s[i].x>>s[i].y;
	}
	sort(s + 1,s + m + 1,cmp);
	int cnt = 0,ans = 1,sum = 1;
	int qwq = 0;
	for (int i = 1;i < m;i++){
		if (s[i].x == s[i + 1].x){
			if (s[i].y != s[i + 1].y){
				ans = 0;
				break;
			}
		}
		else{
			int l = s[i + 1].x - s[i].x;
			/*
			int x = fastpow(v,l - 1);
			int y = (fastpow(v,l * 2 - 1) * (v - 1)) % MOD;
			ans = (ans * x) % MOD;
			ans = (ans * y) % MOD;
			int x = fastpow(v,l * 2);
			int y = fastpow(v,l * 2 - 1);
			int z = fastpow(v,l * 2 - 2);
			ans = (ans * (x - y + z + MOD) % MOD) % MOD;
			*/
			if (l == 1){
				ans = (ans * ((v - 1) * v + 1)) % MOD;
			}
			else{
				ans = (ans * (fastpow(v,l * 2) - fastpow(v,l) * (v - 1))) % MOD;
			}
		}
	}
	ans = (ans * fastpow(v,(s[1].x - 1) * 2)) % MOD;
	ans = (ans * fastpow(v,(n - s[m].x) * 2)) % MOD;
	//cout<<"cnt="<<cnt<<'\n';
	cout<<ans<<'\n';
}

signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int t;
	cin>>t;
	while (t--){
		slove();
	}
	return 0;
}
