#include<algorithm>
#include<stdio.h>
#define ll long long
#define N 100005
using namespace std;
ll read() {
	char c=getchar(); ll x=0, y=1;
	while(!(c >= '0' && c <= '9' || c == '-')) c=getchar();
	if(c == '-') y=-1, c=getchar();
	while(c >= '0' && c <= '9') x=x*10+c-'0', c=getchar();
	return x*y;
}
int T;
ll n, m, v;
struct node {
	int x, y;
} a[N];
bool cmpn(node x, node y) {return x.x < y.x;}
const ll mod=1e9+7;
ll fp(ll x, ll y) {
	ll ans=1;
	for(; y; y>>=1) {
		if(y&1) ans=ans*x%mod;
		x=x*x%mod;
	}
	return ans;
} 
ll f[N];
int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	T=read();
	int i;
	while(T--) {
		n=read(), m=read(), v=read();
		for(i=1; i<=m; i++) a[i].x=read(), a[i].y=read();
		sort(a+1, a+m+1, cmpn);
		ll sum=1;
		for(i=1; i<m; i++) {
			if(a[i+1].x == a[i].x) {if(a[i+1].y != a[i].y) {sum=0; break;} continue;}
			ll num1=fp(v, a[i+1].x-a[i].x-1)*(v-1)%mod, num2=fp(v*v%mod, (a[i+1].x-a[i].x));
			sum=sum*(num2-num1+mod)%mod;
		}
		ll num=fp(v*v%mod, n-a[m].x); sum=sum*num%mod;
		num=fp(v*v%mod, a[1].x-1); sum=sum*num%mod;
		printf("%lld\n", sum);
	}
	return 0;
}

