#include <bits/stdc++.h>

typedef long long ll;
 
using namespace std;
 
//const int MAX=INT_MAX;
 
//const ll MAX=100000000000;
 
//const int mod = 1000000007;
//const int mod = 998244353;
 
//const ll A=100000000000;


const int INF=1000000000;

ll extgcd(ll a,ll b,ll& x,ll& y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }else{
        ll d =extgcd(b,a%b,x,y);
        ll prv=x;
        x=y;
        y=prv-a/b*y;
        return d;
    }
    
}



int main(){
    
    int T;
    cin>>T;
    
    ll N,S,K;
    
    
    for(int t=0;t<T;t++){
        cin>>N>>S>>K;
        
        ll x=0;
        ll y=0;
        ll g=extgcd(N,-K,x,y);
        if(S%g!=0){
            cout<<-1<<endl;
        }else{
            ll s=S/g;
            ll n=N/g;
            ll k=K/g;
            ll nx=x*s;
            ll ny=y*s;
            
           // cout<<"ny:"<<ny<<"n:"<<n<<endl;
           
            
            ll t;
            if(n>0){
            if(-double(ny)/double(n)<0){
                t=-ny/n;
            }else{
                t=-ny/n+1;
            }
            }else{
                if(-double(ny)/double(n)<0){
                    t=-ny/n-1;
                }else{
                    t=-ny/n;
                }
                
            }
            
           // cout<<t<<endl;
            
            
           ll ans=n*t+ny;
            
            

           // cout<<g<<":"<<s<<":"<<x<<":"<<y<<":"<<ans<<endl;
            cout<<ans<<endl;
            
        }
    }
}
   

#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SIZE(x) ll(x.size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<double> x(N), y(N);
    rep(i, N) cin >> x[i] >> y[i];

    rep(i, N) {
        repd(j, i + 1, N) {
            repd(k, j + 1, N) {
                double l = (y[j] - y[i]) * (x[k] - x[i]);
                double r = (y[k] - y[i]) * (x[j] - x[i]);
                if (r == l) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;
    return 0;
}