#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int p=1e9+7;
pair<int,int> a[100005];
int t,n,m,k;
bool fl;
long long sum;
long long qpow(int x,int y){
	long long k=x,l=y,sum=1;
	while(l){
		if(l&1) sum=sum*k%p;
		k=k*k%p;
		l>>=1;
	}
	return sum;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		sum=1;
		fl=0;
		scanf("%d%d%d",&m,&n,&k);
		for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y);
		if(n==1) printf("%lld\n",qpow(1ll*k*k%p,m-1));
		else{
			sort(a+1,a+1+n);
			a[0].x=1;
			a[n+1].x=m;
			for(int i=0;i<=n;i++){
				if(i>0&&i<n&&a[i].x==a[i+1].x&&a[i].y!=a[i+1].y){
					fl=1;
					puts("0");
					break;
				}
				if(a[i].x+1==a[i+1].x) sum=sum*((1ll*k*(k-1)+1)%p)%p;
				else if(a[i].x!=a[i+1].x) sum=sum*qpow(1ll*k*k%p,a[i+1].x-a[i].x)%p;
			}
			if(fl) continue;
			printf("%lld\n",sum);
		} 
	}
	return 0;
}
