#include <bits/stdc++.h>

using namespace std;

uint64_t FindSum(const uint64_t a, const uint64_t b, const uint64_t c) {
    uint64_t k = (c * (c + 1) / 2);
    k %= 998244353;

    uint64_t j = (b * (b + 1) / 2);
    j %= 998244353;

    j = j * k;
    j %= 998244353;

    uint64_t i = (a * (a + 1) / 2);
    i %= 998244353;

    i = i * j;
    i %= 998244353;

    return i;
}

int main() {
    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    cout << FindSum(a, b, c) << '\n';
}

#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<long double, long double>;
using Tiib = tuple<int, int, bool>;
using vvl = vector<vector<ll>>;
const int INF = 2001001007;
const int modd = 1000000007;
const long long modl = 1000000007LL;
const long long mod = 998244353LL;
const ll inf = 1e18;
template <typename AT>
void priv(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void privv(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[i].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[i].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){return (a <= x && x < b);}
template <typename SS>
void sor(vector<SS> &ar){sort(ar.begin(),ar.end());}
template <typename SSS>
void rev(vector<SSS> &ar){reverse(ar.begin(),ar.end());}

void yes(){cout << "Yes" << endl;}
void no (){cout << "No" << endl;}
void yn (bool t){if(t)yes();else no();}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

ll h(ll a, ll b){
    a *= -1LL;
    ll ans = b / a;
    ans = -a * ans + b;
    if (ans < 0) ans += a;
    return ans;
}

int main(){
    int t; cin >> t;
    vector<ll> ans(t);vector<ll> d(t);
    rep(i,t){
        ll n, s, k; cin >> n >> s >> k;
        if (s % gcds(n,k) == 0LL){
            ll x, y;
            ll dd = extGCD(n,k,x,y); d[i] = dd;
            ll a = s / gcds(n,k);
            x *= a; y *= a; 
            ans[i] = h(-n/dd,-y);
        }
        else ans[i] = -1;
    }
    rep(i,t) cout << ans[i] << endl;
}