#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define trace(...) debug(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void debug(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void debug(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " | ";
  debug(comma + 1, args...);
}
#define mp(x,y) make_pair(x,y)
const int INF=1000000000+5;
const int N=1e6+5;
const ll oo=1e18+5;
const ll mod=998244353;

ll gcd(ll a,ll b,ll& num1,ll& num2){
	if(b==0){
		num1=1;
		num2=0;
		return a;
	}
	ll x,y;
	ll g=gcd(b,a%b,x,y);
	num1=y;
	num2=x-y*(a/b);
	return g;
}

void solve(){
	ll n,s,k;
	cin>>n>>s>>k;
	//~ s+a*k==b*n
	//~ b*n-a*k=s;
	//~ s%gcd(n,k)==0
	//~ b*n/g-a*k/g=s/g
	//~ b'*n-a'*k=1
	ll num1,num2;
	ll g=gcd(k,n,num1,num2);
	if(s%g){
		cout<<-1<<endl;
		return;
	}
	num1*=s/g;
	num2*=s/g;
	n/=g;
	k/=g;
	if(num1>=0){
		ll w=num1/n;
		num1-=w*n;
		num1-=n;
		num1=-num1;
	}
	else{
		ll w=abs(num1)/n;
		num1+=w*n;
		num1=-num1;
	}
	cout<<num1<<endl;
}
	

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int t;
	cin>>t;
	while(t--) solve();
	return 0;	
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FOR(i, a, b) for(int i = a; i < b; i++)
ll MOD = 1000000007;
 
ll power(ll base, ll n){
	if (n == 0) return 1;
	if (n == 1) return base;
	ll halfn = power(base, n/2);
	if (n % 2 == 0) return (halfn * halfn) % MOD;
	return (((halfn * halfn) % MOD) * base) % MOD;
}
 
ll inverse(ll n){
	return power(n, MOD-2);
}

int main(){
	ios::sync_with_stdio(false);
	int a, b, c; cin >> a >> b >> c;
	double dp[101][101][101];
	FOR(i, 0, 101){
		FOR(j, 0, 101){
			FOR(k, 0, 101){
				dp[i][j][k] = 0;
			}
		}
	}
	dp[99][99][99] = 1;
	for (int i = 99; i >= 0; i--){
		for (int j = 99; j >= 0; j--){
			for (int k = 99; k >= 0; k--){
			    if (i == 99 && j == 99 && k == 99){
			        dp[i][j][k] = 1; continue;
			    }
				if (a > 0) dp[i][j][k] += (dp[i+1][j][k] + 1) * i;
				if (b > 0) dp[i][j][k] += (dp[i][j+1][k] + 1) * j; 
				if (c > 0) dp[i][j][k] += (dp[i][j][k+1] + 1) * k;
				dp[i][j][k] = dp[i][j][k] / (i+j+k);
			}
		}
	}
	cout << setprecision(18) << dp[a][b][c] << '\n';
	return 0;
}