import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter ou = new PrintWriter(System.out); int s = Integer.parseInt(sc.next()); for(int q = 0 ; q < s ; q++){ int n = Integer.parseInt(sc.next()); int m = Integer.parseInt(sc.next()); int x = Integer.parseInt(sc.next()); long zz = 1; long zzz = 1 + m; long yyy = 1 - m; long yy = 1; while(n != 0){ if(n % 2 != 0){ zz *= zzz; yy *= yyy; zz %= (int)Math.pow(10 , 9) + 7; yy %= (int)Math.pow(10 , 9) + 7; } n /= 2; zzz *= zzz; yyy *= yyy; zzz %= (int)Math.pow(10 , 9) + 7; yyy %= (int)Math.pow(10 , 9) + 7; } if(x == 0) zz += yy; else zz -= yy; while(zz < 0) zz += (int)Math.pow(10 , 9) + 7; if(zz % 2 == 1) zz += (int)Math.pow(10 , 9) + 7; zz /= 2; zz %= (int)Math.pow(10 , 9) + 7; ou.println(zz); } ou.flush(); sc.close(); } }