#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) templatebool chmax(T &x, T y){if(x>=y)return false;x=y;return true;} templatebool chmin(T &x, T y){if(x<=y)return false;x=y;return true;} const long long mod = 998244353; long long modpow(long long n, long long r){ long long ans = 1; while(r){ if(r%2)ans = ans * n % mod; n = n * n % mod; r /= 2; } return ans; } int main(){ int T; long long A, B, K, a, b; cin >> T; while(T--){ cin >> A >> B >> K; if(abs(A)!=1&&abs(B)!=1)a = (abs(A)/(abs(B)-1)+abs(A))/abs(A); else a = 0; b = a*abs(A); if(A==0||A<0&&B>=0){ cout << 0 << endl; }else if(B>1){ if(a > K){ cout << K*A%mod << endl; }else{ cout << a*A%mod*modpow(B%mod, (K-a))%mod << endl; } }else if(B>=0){ cout << K*A%mod << endl; }else if(B==-1){ if(A>0)cout << A*K%mod << endl; else cout << (-A)*(K-1)%mod << endl; }else if(A>0){ if(a > K){ cout << K*A%mod << endl; }else if((K-a)%2){ if((b+A)/B/B>=(b-A)||a==0)cout << (a+1)*A%mod*modpow(-B%mod, (K-a-1))%mod << endl; else cout << (a-1)*A%mod*modpow(-B%mod, (K-a+1))%mod << endl; }else{ cout << a*A%mod*modpow(B%mod, (K-a))%mod << endl; } }else{ if(a > K){ cout << (K-1)*A%mod*(-B)%mod << endl; }else if((K-a)%2){ if((b-A)/B/B>=(b+A)||a==0)cout << (a+1)*A%mod*modpow(-B%mod, (K-a-1))%mod << endl; else cout << (a-1)*(-A)%mod*modpow(-B%mod, (K-a+1))%mod << endl; }else{ cout << (a+1)*A%mod*modpow(-B%mod, (K-a-1))%mod << endl; } } } }