#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,t,m,v,c[100010],d[100010];
bool a[100010],cnt;
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d%d%d",&n,&m,&v);
		memset(a,0,sizeof(a));
		cnt=0;
		for(int i=1;i<=m;i++){
			scanf("%d%d",&c[i],&d[i]);
			if(a[c[i]]){
				cnt=1;
			}
			a[c[i]]=1;
		}
		if(cnt) {
			cout<<0<<endl;
			continue;
		}
		if(m==n) cout<<1<<endl;
		int k=0;
		k=(n-m)*v%mod;
		k=k*v%mod;
		k=k*(n-m)%mod;
		cout<<k<<endl;
	}
	
	return 0;
}
