mod = 10**9 + 7 def solve(): n, m, x = map(int, input().split()) t = pow(m + 1, n, mod) d = pow(m - 1, n, mod) print((t + (1 - (x + n) % 2 * 2) * d) * pow(2, mod - 2, mod) % mod) s = int(input()) for i in range(s): solve()