#include <iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <set>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repp(i, s, n) for(int i = (int)s; i < (int)n; i++)
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
using ll = long long;

int main(void){
    double x, y, z;
    cin >> x >> y >> z;
    int ans = (y / x)*z;
    if (((double)ans/z) == (y/x))ans--;
    cout << ans << endl;
}
/**
 *    author:  doublevgp
 *	  Which can not destroy me will make me strong
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>

const double PI = acos(-1.0);
const double eps = 1e-6;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
const int maxm = 100 + 10;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll extgcd(ll a, ll b, ll &x, ll &y) {
	if (b == 0) {
		x = 1, y = 0;
		return a;
	}
	ll g = extgcd(b, a % b, x, y);
	ll t = x;
	x = y;
	y = t - a / b * y;
	return g;
}
ll n, s, k;
void sol() {
	cin >> n >> s >> k;
	ll x, y;
	ll g = extgcd(k, n, x, y);
	if (s % g != 0) {
		cout << -1 << endl;
		return ;
	}
	else if (g == 1) {
		cout << (x * (-s) % n + n) % n << endl;
	}
	else {
		n /= g;
		s /= g;
		k /= g;
		cout << (x * (-s) % n + n) % n << endl;
	}
	return ;
}

int main()
{
	ios;
	int t;
	cin >> t;
	while (t--) {
		sol();
	}
	return 0;
}