#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

typedef vector<ll> vl;
typedef pair<ll, ll> pll;

#define St first
#define Nd second
#define Pb push_back
#define print_pair(p) "{" << (p).St << ", " << (p).Nd << "} "
#define list_format(i, n) (i!=n? " ":"\n")
#define endl "\n"
#define sz(a) (int)a.size()

#define REP(i,a,b) for(int i = a; i <= b; i++)
#define REV(i,a,b) for(int i = a; i >= b; i--)

#define AritSum(a,d,n) ((n)*(2*(a)+((n)-1)*(d)))/2
#define Log(base, num) log2(num)/log2(base)

#define MOD 1000000007
#define INF 1e9 + 7

// ******************** Add-on *****************************

// ******************** Add-on *****************************

// ************* MAIN *******************

ll modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
        return 0; 
  
    while (a > 1) { 
        // q is quotient 
        ll q = a / m; 
        ll t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
        x += m0; 
  
    return x; 
} 

ll gcd(ll a, ll b) {
    if (a < b) return gcd(b, a);
    if (b == 0) return a;
    return gcd(b, a % b);
}

void solve() {
    ll n, s, k; cin >> n >> s >> k;

    ll d = gcd(n, gcd(s, k));
    n /= d;
    s /= d;
    k /= d;

    if (gcd(n, k) != 1) {
        cout << -1 << endl;
        return;
    }

    ll inv = modInverse(k, n);

    cout << (inv * (n - s)) % n << endl;
}

/*
g++ -std=c++14 -Wall -Wextra -O2 Test.cpp -o Test
./Test < in.txt

*/
int main() {    
    int _=1;
    cin>>_;
    REP(t,1,_) {
        // cout << "Case #" << t << ": ";
        solve();
        // cout << ((solve())? "YES" : "NO") << endl;
    }
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define fr(i,t) for(i=0;i<t;i++)
#define fr1(i,r,t) for(i=r;i<t;i++)
typedef long long int lli;
typedef unsigned long long int ulli;
#define inf LONG_MAX
#define ff first
#define ss second 
double pie=3.14159265358979323846;
#define dbug(x) cout<<#x<<"="<<x<<endl;
#define dbug2(x,y) 
// lli M=1e9+7;
lli M=998244353;
#define gg cout<<"Case #"<<i+1<<": "
#define exact(x) cout<<fixed<<setprecision(8)<<x<<endl

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	lli T,n,i,j,k=0,m,j1,co=0,check,mi,l,sum;
	lli ans=0;
    // cin>>T;
    // fr(i,T)
    // {
        cin>>n>>m>>k;
        ans=((k*(k+1))/2)%M;
        ans=(ans*(((m*(m+1))/2)%M))%M;
        ans=(ans*(((n*(n+1))/2)%M))%M;
        cout<<ans<<endl;
    // }   
}
