const MOD: usize = 1e9 as usize + 7; fn power(base: usize, times: usize) -> usize { if times == 0 { return 1usize; } if times == 1 { return base; } let temp = power(base, times/2); temp * temp % MOD * power(base, times%2) % MOD } fn solve(mod2: usize) -> usize { let mut nmx = String::new(); std::io::stdin().read_line(&mut nmx).ok(); let nmx: Vec = nmx.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nmx[0]; let m = nmx[1]; let x = nmx[2]; if x == 0 { (power(1+m, n) + power((MOD+1-m) % MOD, n)) % MOD * mod2 % MOD } else { (MOD + power(1+m, n) - power((MOD+1-m) % MOD, n)) % MOD * mod2 % MOD } } fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s: usize = s.trim().parse().unwrap(); let mut result = Vec::with_capacity(s); let mod2 = power(2, MOD-2); for _ in 0..s { result.push(solve(mod2)); } for &v in result.iter() { println!("{}", v); } }