#include <iostream>
#include <cstdio>
using namespace std;
const int mod=1e9+7;
const int M=100010;
int n,m,c[M],d[M],cnt,a[101],b[101];
long long v;
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;
	scanf("%d",&T);
	while( T-- ) {
		scanf("%d%d%lld",&n,&m,&v);
		for(int i=1;i<=n;i++) scanf("%d%d",&c[i],&d[i]);
		if( m==n ) {
			long long temp=(v*(v-1)%mod+1)%mod;
			long long ans=0;
			for(int i=1;i<n;i++) {
				if( i==1 ) ans=temp;
				else ans=(ans*temp)%mod;
			}
			printf("%lld\n",ans); 
		} else {
			printf("0\n");
		}
	}
	return 0;
}
