CSES - Shared codeLink to this code: https://cses.fi/paste/818f3827d9b37859131da6/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Temp {
	//-------------------
	public static final int MOD = (int) (1e9+7);
	// ------------------
	 
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);
    
    
    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
 
    int nextInt() {
        return Integer.parseInt(next());
    }
 
    long nextLong() {
        return Long.parseLong(next());
    }
 //------------------
    public static void main(String[] args) {
        Temp ob = new Temp();
        ob.run();
    }
    private void run() {
    	int n = nextInt();
    	while(n-->0) {
    		int a = nextInt();
    		int b = nextInt();
    		int c = nextInt();
    		out.println(exp(a, exp(b,c, MOD-1), MOD));//fermat theorem
    	}
//    	out.println();
    	out.close();
    }
    private long exp(long a, long b, int mod) {
    	
    	long res =1;
    	while(b>0) {
    		if((b%2)==1) {
    			res *=a;
    			res %=mod;
    		}
    		a = a*a;
    		a %= mod;
    		b /= 2;
    	}
    	return res;
    }
	
}