#include<iostream>
#include<string.h>
#include<map>
using namespace std;
#define N 100010
#define M 1000000007
#define LL long long
LL T,n,m,v,c,d,ans,o;
map<LL,int> a;
LL p(LL x,LL y){
	LL u=1;
	while(y!=0){
		if(y&1) u=(u*x)%M;
		x=(x*x)%M;
		y/=2;
	}
	return u;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		bool t=1;
		ans=0;
		scanf("%lld%lld%lld",&n,&m,&v);
		o=0;
		for(LL i=1;i<=n;i++) a[i]=0;
		for(LL i=1;i<=m;i++){
			scanf("%lld%lld",&c,&d);
			if(a[c]!=0&&a[c]!=d) t=0;
			else{
				a[c]=d;
				if(a[c-1]!=0) o++;
				if(a[c+1]!=0) o++;
			}
		}
		if(!t){
			printf("0\n");
			continue;
		}
		ans=(p((v*v)%M,n-o-1)%M*p(v*v-v+1,o))%M;
		printf("%lld\n",ans);
	}
	return 0;
}
