#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int ans;
int t,n,m,v;
int c[100016],d[100016];
int f[1000016],g[100016];
int qp(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)
		{
			ret=ret*a%mod;
		}
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
void init()
{
	f[0]=g[0]=1;
	for(int i=1;i<=100015;i++)
	{
		f[i]=f[i-1]*i%mod;
		g[i]=g[i-1]*qp(i,mod-2)%mod;
	}
}
int C(int n,int m)
{
	return f[n]*g[n-m]%mod*g[m]%mod;
}
signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>t;
	init();
	while(t--)
	{
		cin>>n>>m>>v;
		ans=0;
		if(n==m)
		{
			for(int i=1;i<=m;i++)
			{
				cin>>c[i]>>d[i];
			}
			int sum=1;
			for(int i=1;i<n;i++)
			{
				sum=sum*(v-1)%mod*(v-1)%mod*C(n-1,i)%mod;
				ans=(ans+sum)%mod;
			}
			cout<<ans<<endl;
		}
		else
		{
			cout<<0<<endl;	
		}
	}
} 
