class Integer def mod_inverse(mod) pow(mod - 2, mod) end end S = gets.to_i MOD = 10 ** 9 + 7 S.times do n, m, x = gets.split.map(&:to_i) if x == 0 puts ((m + 1).pow(n, MOD) + (m - 1).pow(n, MOD)) * 2.mod_inverse(MOD) % MOD else puts ((m + 1).pow(n, MOD) + (m - 1).pow(n, MOD)) * 2.mod_inverse(MOD) % MOD end end