#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { long long x = 2; long long y = 1000000005; long long two = 1; while (y > 0) { if ((y & 1) == 1) { two = two * x % 1000000007; } x = x * x % 1000000007; y >>= 1; } int s; cin >> s; for (int i = 0; i < s; i++) { long long n, m, x1; cin >> n >> m >> x1; x = m + 1; y = n; long long ans = 1; while (y > 0) { if ((y & 1) == 1) { ans = ans * x % 1000000007; } x = x * x % 1000000007; y >>= 1; } x = m - 1; y = n; long long ans1 = 1; while (y > 0) { if ((y & 1) == 1) { ans1 = ans1 * x % 1000000007; } x = x * x % 1000000007; y >>= 1; } long long ans2 = ans; ans -= ans1; ans %= 1000000007; if (ans < 0)ans += 1000000007; ans = ans * two % 1000000007; if (n % 2 == x1) { ans = ans2 - ans; ans %= 1000000007; if (ans < 0)ans += 1000000007; } cout << ans % 1000000007 << endl; } return 0; }