#include<bits/stdc++.h>
#define rep(i , m , n) for(register int i = m; i <= n; i++)

using namespace std;
int T;
const int MOD = 1e9 + 7;
long long fpow(int x , int y){
	long long ans = 1 , tmp = x;
	while(y){
		if(y % 2 == 1)(ans *= tmp) %= MOD;
		y /= 2;
		(tmp *= tmp) %= MOD;
	}
	return ans;
}
long long ans;
struct data{
	int x , y;
}t[100005];
bool cmp(data a , data b){
	return a.x < b.x;
}
int a[100005];
long long f[100005];
int main(){
	freopen("assign.in" , "r" , stdin);
	freopen("assign.out" , "w" , stdout);
	scanf("%d" , &T);
	while(T--){
		ans = 0;
		memset(f , 0 , sizeof f);
		
		int n , m , v;
		scanf("%d%d%d" , &n , &m , &v);
		
		rep(i , 1 , m)scanf("%d%d" , &t[i].x , &t[i].y);
		sort(t + 1 , t + 1 + m , cmp);
		int N = 0;
		rep(i , 1 , m){
			if(t[i].x != t[i - 1].x)N++ , a[N] = t[i].x;
			if(t[i].x == t[i - 1].x && t[i].y != t[i - 1].y)ans = -1;
		}
		if(ans == -1){
			printf("0\n");
			continue;
		}
		f[1] = 0;
		rep(i , 2 , N){
			long long tmp = (fpow(v , (a[i] - a[i - 1] - 1)) * (v - 1)) % MOD;
			f[i] = (fpow(v , (a[i - 1] - 1) * 2) * tmp) % MOD;
			(f[i] += (f[i - 1] * (fpow(v , (a[i] - a[i - 1]) * 2) - tmp + MOD)) % MOD) %= MOD;
		}
		(ans = (fpow(v , (a[N] - 1) * 2) - f[N] + MOD) * fpow(v , (n - a[N]) * 2)) %= MOD;
		printf("%lld\n" , ans);
	}
	
	return 0;
}
