#include<bits/stdc++.h>
using namespace std;
long long T,n,m,v;
long long mod = 1e9+7;
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld%lld",&n,&m,&v);
		long long ans=1;
		for(int i=1;i<n;i++){
			ans = ans*((v-1)*v+1)%mod;
			ans%=mod;
		}
		printf("%lld\n",ans);
	}
	fclose(stdin);
	fclose(stdout); 
	return 0;
}
