#include <bits/stdc++.h>

#define mid(l,r) ((l + r) >> 1)
#define lsb(x) (x & (-x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define FOR(X,L,R) for(int X=L;X<R;++X)
#define endl '\n'
#define int long long
#define MOD ((int)1e9 + 7)
#define INF (0x3f3f3f3f)
#define LLINF (0x3f3f3f3f3f3f3f3fLL)

using namespace std;

template<typename T>
inline void input(vector<T>& v)
{
    for(T& x: v)
        cin >> x;
}

void solve()
{
    int a, b, w; cin >> a >> b >> w;

    if((1000 * w  + b - 1) / b > (1000 * w) / a) cout << "UNSATISFIABLE" << endl;
    else cout << (1000 * w  + b - 1) / b << " " << (1000 * w) / a << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    #if defined(CODEFORCES) || defined(CF)
        int t; cin >> t;
        while(t--) solve();
    #else
        solve();
    #endif

    return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9+7;

int solve_naive(const int n, const int s, const int k){
    int cnt = 0;
    ll now = s;
    while (now % n != 0 && cnt < n){
        now += k;
        cnt += 1;
    }
    if (cnt >= n){
        return -1;
    }
    return cnt;
}

ll _gcd(ll a, ll b){ return (a%b) ? _gcd(b, a%b) : b; }
pair<ll, ll> extgcd(ll a, ll b){
    // ax+by=gcd(a, b)なるx, yを求める
    if(a%b==0)return {0, 1}; // a*0+b*1=b
    const auto [x, y] = extgcd(b, a%b); // b*x + (a-a/b*b)*y = gcd(a, b)
    return {y, x-a/b*y}; // a*y + b*(x+a/b*y) = gcd(a, b)
}
ll powmod(ll x, ll n, ll p){
    // return (x ** n) mod p
    if (n==0)return 1;
    if(n==1)return x%p;
    const auto y = powmod(x, n/2, p);
    return (y*y%p)*powmod(x, n%2, p)%p;
}

int solve(int n, int s, int k){
    // s + a * k == 0 mod n なる最小の a を求める
    const auto g = _gcd(k, n);
    if(s%g!=0){
        // k, n が g の倍数なので s は g の倍数である必要がある
        return -1;
    }
    if(g>1){
        return solve(n/g, s/g, k/g);
    }
    // k*a == 1 mod n なる a を求める
    const auto [a, _] = extgcd(k, n);
    return ((n-s)*a%n+n)%n;
}

int main()
{
    int t;
    cin >> t;
    for(int ti=0; ti<t; ti++){
        int n,s,k;
        cin >> n >> s >> k;
        cout << solve(n, s, k) << endl;
    }
    return 0;
}