#include #include #include #define int long long #define rep(i, n) for(i = 0; i < n; i++) using namespace std; using namespace atcoder; using mint = modint998244353; const int INF = (1LL << 62); int naive1(int K, int a, int b) { int ret = -INF, i, j; rep(i, (1 << K)) { int score = 0; rep(j, K) { if ((i >> j) % 2 == 0) { score += a; } else { score *= b; } } ret = max(ret, score); } return ret; } int naive2(int K, int a, int b) { int ret = 0; for (int i = 0; i <= K; i++) { int score = 0, j; rep(j, K) { if (j < i) score += a; else score *= b; } ret = max(ret, score); } return ret; } mint solve(int K, int a, int b) { if (b == 0 || b == 1) { if (a > 0) return K * a; return 0; } if (b >= 2) { if (a > 0) return a * mint(b).pow(K - 1); return 0; } if (b == -1) { if (a > 0) return K * a; return (K - 1) * a * (-1); } if (b <= -2 && K % 2 == 0) { if (a > 0) return 2 * a * mint(b).pow(K - 2); return a * mint(b).pow(K - 1); } if (b <= -2 && K == 1) { if (a > 0) return a; return 0; } if (a > 0) return a * mint(b).pow(K - 1); return 2 * a * mint(b).pow(K - 2); } void test() { int mod = 998244353; for (int K = 1; K <= 10; K++) { for (int a = -50; a <= 50; a++) { for (int b = -50; b <= 50; b++) { int res1 = naive2(K, a, b); int res2 = solve(K, a, b).val(); if (res1 % mod != res2) { cout << "WA" << endl; cout << "K: " << K << ", a: " << a << ", b: " << b << endl; cout << "naive: " << res1 << ", naiveMod: " << res1 % mod << endl; cout << "solve: " << res2 << endl; return; } } } } cout << "AC" << endl; } signed main() { int T; cin >> T; while (T--) { int a, b, K; cin >> a >> b >> K; cout << solve(K, a, b).val() << endl; } return 0; }