#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const long long N=1e5+5;
const ull MOD=1e9+7;
ull n,m,v,a,b,c;
ull ans;
struct one{
	long long c,d;
}o[N];
bool cmp(one a,one b){return a.c<b.c;}
void work(){
	scanf("%lld%lld%lld",&n,&m,&v);
	ans=1;
	a=v*v,b=v*v-v+1,c=2*v*v-v;
	for(ull i=1;i<=m;i++){
		scanf("%lld%lld",&o[i].c,&o[i].d);
	}
	sort(o+1,o+1+m,cmp);
	for(ull i=1;i<=m;i++){
		if(o[i].c==o[i+1].c&&o[i].d!=o[i+1].d){
			printf("0\n");
			return ;
		}
	}
	if(m==1){
		for(int i=1;i<n*2-1;i++)
			ans*=2;
		printf("%lld\n",ans);
		return ;
	}
	for(int i=1,j=1;i<n;i++){
		if(o[j].c==i){
			j++;
			if(o[j].c==i+1){
				ans=ans*b%MOD;
			}
			else{
				ans=ans*a%MOD;
			}
		}
		else{
			if(o[j].c==i+1){
				ans=ans*a%MOD;
			}
			else{
				ans=ans*c%MOD;
			}
		}
	}
	printf("%lld\n",ans);
	return ;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int t;
	scanf("%d",&t);
	while(t--)work();
	return 0;
}
/*
1
5 1 2
1 2
*/
