#include #include #include #include using namespace std; using namespace atcoder; using ll = long long; using lb = long double; using P = pair; using T = tuple; using vll = vector; using vb = vector; using vvll = vector>; using vP = vector

; using Graph = vector>; using WGraph = vector>>; // コスト、頂点番号の順 using mint = modint998244353; //using mint = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) mt19937_64 rng(58); long double PI = 3.14159265358979; const ll LLMAX = 9223372036854775807; const ll INF = 1e18; vector di = {-1, 0, 1, 0}; // 上左下右 vector dj = {0, -1, 0, 1}; template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } void solve() { ll a, b, k; cin >> a >> b >> k; mint ans = 0; if (k == 0 || a == 0) { cout << 0 << endl; return; } if (a < 0 && b >= 0) { cout << 0 << endl; return; } if (b == 0) { if (a <= 0) cout << ans.val() << endl; else { ans = (mint)a * (mint)k; cout << ans.val() << endl; } return; } if (b == 1) { ans = (mint)a * (mint)k; cout << ans.val() << endl; return; } if (b == -1) { if (a > 0) { ans = (mint)a * (mint)(k); cout << ans.val() << endl; } else { if (k == 1) cout << 0 << endl; else { ans = (mint)a * (mint)(k - 1); cout << ans.val() << endl; } } return; } ll A = abs(a); ll B = abs(b); k--; ll cur = A; ll cnt = 0; if (a < 0) cnt++; if (b < 0) cnt += k; vector Rb(40); Rb[0] = B; rep (i, 39) Rb[i + 1] = Rb[i] * Rb[i]; auto power = [&](ll x) { mint res = 1; rep (i, 40) { if ((x >> i) & 1) res *= Rb[i]; // ansにしてた } return res; }; if (cnt % 2 == 0) { ans = (mint)cur * power(k); } else { ans = (mint)(cur + A) *power(k - 1); } cout << ans.val() << endl; } int main() { ll t; cin >> t; rep (ti, t) solve(); return 0; }