#include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int, int>
#define mkp make_pair
#define sz(x) ((int) x.size())
#define be(x) x.begin()
#define en(x) x.end()
using namespace std;
const int N = 1e5 + 7; 
int n, m;
void exgcd(ll a, ll b, ll &x, ll &y) {
	if(b == 0) return x = 1, y = 0, void();
	exgcd(b, a % b, y, x), y -= x * (a / b);
}
ll mul(ll aa, ll bb, ll mod) {
	ll sav = aa * bb - (ll)( (long db) aa * bb / mod + 0.2 ) * mod;
	return sav < 0 ? sav + mod : sav;
}
ll crt(ll *a, ll *b, int len) { // x mod a_i = b_i
	ll now = 1, ys = 0;
	L(i, 1, len) {
		ll g = __gcd(now, a[i]), c1, c2, md = a[i] / g;
		if((b[i] - ys) % g) return 2e18;
		exgcd(now, a[i], c1, c2), ((c1 %= md) += md) %= md, c1 = mul(c1, ((b[i] - ys) / g % md + md) % md, md);
		((c1 %= md) += md) %= md, ys += c1 * now;
		now /= g, now *= a[i], ((ys %= now) += now) %= now;
	}
	return ys;
}
ll a[N], b[N];
int T, x, y, p, q;
ll ans = 0;
void Main() {
	ans = 2e18;
	cin >> x >> y >> p >> q;
	L(i, x, x + y - 1) L(j, p, p + q - 1) {
		a[1] = 2 * (x + y), b[1] = i;
		a[2] = p + q, b[2] = j;
		ans = min(ans, crt(a, b, 2));
	}
	if(ans == 2e18) cout << "infinity\n";
	else cout << ans << "\n";
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> T;
	while(T--) Main();
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
int p,q,t,x,y;
ll a[3],ans,g,m[3];
template<class T>
inline T slow_add(T a,T b,T mod){
	while(a>mod-b)a-=mod;
	return a+b;
}
template<class T>
inline T slow_mul(T a,T b,T mod){
	T ret=0;
	for(;b;a=(a+a)%mod,b>>=1)if(b&1)ret=(ret+a)%mod;
	return ret;
}
template<class T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>
void exgcd(T a,T b,T &x,T &y){
	a%=b;
	if(!a){
		x=b;y=0;
		return;
	}
	ll s=b,t=a,m0=0,m1=1;
	while(t){
		ll u=s/t;
		s-=t*u;
		m0-=m1*u;
		ll tmp=s;
		s=t;
		t=tmp;
		tmp=m0;
		m0=m1;
		m1=tmp;
	}
	if(m0<0)m0+=b/s;
	x=s,y=m0;
}
inline ll cn(int n){
	ll mul=1,ret=0;
	for(ri i=1;i<=n;++i){
		ll a1=a[i]%m[i],m1=m[i];
		if(mul<m1)swap(mul,m1),swap(ret,a1);
		if(mul%m1==0){
			if(ret%m1!=a1)return LLONG_MAX;
			continue;
		}
		ll t1=0,t2=0;
		exgcd(mul,m1,t1,t2);
		ll u1=m1/t1;
		ll tmp=(a1-ret)/t1%u1*t2%u1;
		ret+=tmp*mul;
		mul*=u1;
		if(ret<0)ret+=mul;
	}
	return ret;
}
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d%d%d%d",&x,&y,&p,&q);
		#define a1 a[1]
		#define a2 a[2]
		#define m1 m[1]
		#define m2 m[2]
		m1=(x+y)<<1,m2=p+q;
		g=gcd(m1,m2);
		ans=LLONG_MAX;
		for(a1=x;a1<x+y;++a1)
			for(a2=p;a2<p+q;++a2)
				if((a2-a1)%g==0)
					ans=min(ans,cn(2));
		if(ans==LLONG_MAX)puts("infinity");
		else printf("%lld\n",ans);
	}
	return 0;
}