#include <bits/stdc++.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end());reverse(v.begin(),v.end());}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}

//Cとかで出てみたい
int main() {
	ll R,X,Y;
	cin>>R>>X>>Y;
	R*=R,X*=X,Y*=Y;
	ll K=(X+Y+R-1)/R;
	//cout<<K<<endl;
	ll l=0,r=1e9;
	while(r-l>1){
		ll D=(l+r)/2;
		if(D*D>=K) r=D;
		else l=D;
	}
	if(X+Y<R) cout<<"2"<<endl;
	else cout<<r<<endl;
}



#include <cstdio>
#include <iostream>
using namespace std;
#define int __int128
int T, X, Y, P, Q;

void read( int &x ) {
	x = 0; char s = getchar();
	while( s < '0' || s > '9' ) s = getchar();
	while( '0' <= s && s <= '9' ) {
		x = ( x << 1 ) + ( x << 3 ) + ( s ^ 48 );
		s = getchar();
	}
}

void exgcd( int a, int b, int &d, int &x, int &y ) {
	if( ! b ) d = a, x = 1, y = 0;
	else {
		exgcd( b, a % b, d, y, x );
		y -= x * ( a / b );
	}
}

void print( int x ) {
	if( x > 9 ) print( x / 10 );
	putchar( ( x % 10 ) + '0' );
}

signed main() {
	read( T );
	while( T -- ) {
		read( X ), read( Y ), read( P ), read( Q );
		int d, x, y, ans = 1e32;
		exgcd( X * 2 + Y * 2, P + Q, d, x, y );
		for( int i = 0;i < Y;i ++ )
			for( int j = 0;j < Q;j ++ ) {
				int c = P + j - X - i;
				if( c % d ) continue;
				int k1 = c / d * x;
				int k2 = c / d * ( - y );
				int mod1 = ( P + Q ) / d, mod2 = ( X * 2 + Y * 2 ) / d;
				if( k1 < 0 ) {
					int t = ( - k1 + mod1 - 1 ) / mod1;
					k1 += mod1 * t, k2 += mod2 * t;
				}
				if( k2 < 0 ) {
					int t = ( - k2 + mod2 - 1 ) / mod2;
					k1 += mod1 * t, k2 += mod2 * t;
				}
				k1 %= mod1;
				ans = min( ans, k1 * ( X * 2 + Y * 2 ) + X + i );
			}
		if( ans == 1e32 ) printf( "infinity\n" );
		else print( ans ), putchar( '\n' );
	}
	return 0;
}