typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll a,b,c;
    std::cin >> a>>b>>c;
    
    vector<vector<vector<ld>>> memo(100,vector<vector<ld>>(100,vector<ld>(100,-1)));
    
    function<ld(ll,ll,ll)> rec = [&] (ll a,ll b,ll c) {
        if(a==100||b==100||c==100) return (ld)0;
        if(memo[a][b][c]!=-1)return memo[a][b][c];
        
        return memo[a][b][c] = 1+a/(a+b+c+0.0)*rec(a+1,b,c)+b/(a+b+c+0.0)*rec(a,b+1,c)+c/(a+b+c+0.0)*rec(a,b,c+1);
    };
     
    std::cout <<setprecision(20)<< rec(a,b,c) << std::endl;
}

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, s, k;
    cin >> n >> s >> k;
    int m = sqrt(n) + 1;
    map<int, int> mp;
    int jk = 0;
    for (int j = 0; j < m; ++j) {
        if (mp.count(jk)) break;
        mp[jk] = j;
        jk = (jk + k) % n;
    }
    long long mk = jk;
    for (int i = 0; i < m; ++i) {
        int now = ((-s - mk * i) % n + n) % n;
        if (mp.count(now)) {
            cout << m * i + mp[now] << '\n';
            return;
        }
    }
    cout << -1 << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--) solve();
}