#include<bits/stdc++.h>
#define N 200006
#define LL __int128
#define int long long 
using namespace std;

int T,t;
int X,Y,p,q;
int mod1,mod2;
int ai[12],bi[12];

inline int qr()
{
	char a=0;int w=1,x=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();}
	return w*x;
}

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

LL mul(LL a,LL b,LL mod)
{
	LL ans=0;
	while(b)
	{
		if(b&1)
			ans=(ans+a)%mod;
		a=(a+a)%mod;
		b>>=1;
	}
	return ans;
}

LL excrt()
{
    LL x,y;
    LL M=bi[1],ans=ai[1];
    for(int i=2;i<=2;i++)
    {
        LL a=M,b=bi[i],c=(ai[i]-ans%b+b)%b;
        LL gcd=exgcd(a,b,x,y),bg=b/gcd;
        if(c%gcd!=0) return -1; 
        x=mul(x,c/gcd,bg);
        ans+=x*M;
        M*=bg;
        ans=(ans%M+M)%M;
    }
    return (ans%M+M)%M;
}

signed main()
{
	T=qr();
	while(T--)
	{
		X=qr();
		Y=qr();
		p=qr();
		q=qr();
		mod1=(X+Y)<<1;
		mod2=(p+q);
		LL ans=2e18;
		int opl=0;
		for(register int i=0;i<Y;i++)
		{
			for(register int j=p;j<p+q;j++)
			{
				bi[1]=mod1;
				bi[2]=mod2;
				ai[1]=i+X;
				ai[2]=j;
				LL ans1=excrt();
				if(ans1==-1)
					continue;
				opl=1;
				ans=min(ans1,ans);
			}
		}
		if(opl)
			cout<<(long long)ans<<endl;
		else
			cout<<"infinity"<<endl;
	}
	return 0;
}
#include<bits/stdc++.h>
#define rep(i, n) for (Int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(Int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(Int i=a;i<=Int(b);i++)
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);
//#include <atcoder/all>
//using namespace atcoder;
typedef long long Int;
const long long INF = 1ll << 60;
using namespace std;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  __MAGIC__
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = -1000000;
  ans = max(ans,a-c);
  ans = max(ans,a-d);
  ans = max(ans,b-c);
  ans = max(ans,b-d);
    

  cout << ans << endl;
//  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}