#include<bits/stdc++.h>
#define PII pair<int,int>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
ll ans,n,m,v;
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	while(T--){
		cin >> n >> m >> v;
		if(m == 1){
			ans = 1;
			for(int i = 1; i <= 2*(n-1); ++i){
				ans *= v;
				ans %= mod;
			}
			cout << ans << "\n";
		}
	}
	return 0;
}
