#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include <math.h>
#include<climits>
using namespace std;
#define int long long
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define ff first
#define ss second
#define print(x) cout<<x<<"\n"
#define printt(x,y) cout<<x<<" "<<y<<"\n"
#define printtt(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define pb push_back
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define all(v) v.begin(),v.end()
#define vvi vector<vector<int>>
#define maxq priority_queue<int>
#define minq priority_queue<int,vector<int>,greater<int>>
#define mod 1000000007
#define N 200009

void solve() {
	int n;
	cin >> n;

	if (n < 10) {
		cout << "Yes" << endl; return;
	}

	vi v;
	while (n > 0) {
		v.pb(n % 10);
		n = n / 10;
	}

	int z = v.size();
	int ok = 1;
	for (int i = 0; i < z / 2; i++) {
		//print(v[i]);
		if (v[i] != v[z - i - 1])
			ok = 0;
	}
	if (ok == 1) {
		cout << "Yes" << endl;
		return;
	}

	int c = 0;
	for (int i = 0; i < z; i++)
		if (v[i] != 0)
			break;
		else
			c++;

	//print(c);
	reverse(all(v));
	int i = 0, j = z - 1 - c;
	ok = 1;
	//printt(i, j);
	while (i < j) {
		//printt(v[i], v[j]);
		if (v[i] != v[j])
			ok = 0;
		i++, j--;
	}

	if (ok == 0)
		cout << "No";
	else
		cout << "Yes";



}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll ans=-1;
void Exgcd(ll A,ll B,ll &x,ll &y,ll &d)
{
	if(B==0)
	{
		x=1;y=0;d=A;
		return;
	}
	Exgcd(B,A%B,x,y,d);
	ll tmp=y;
	y=x-(A/B)*y;
	x=tmp;
	
}
void Solve(ll A,ll B,ll C,ll a,ll b)
{
	ll x,y,d;
	Exgcd(A,B,x,y,d);
	if(C%d!=0)return;
	x*=C/d;
	x=(x%(B/d)+(B/d))%(B/d);
	if(ans==-1)ans=A*x+a;
	else ans=min(ans,A*x+a);
}
int main()
{	
	int T;
	cin>>T;
	while(T--)
	{	
		ans=-1;
		ll X,Y,P,Q,A,B;
		cin>>X>>Y>>P>>Q;
		A=2ll*X+2ll*Y;
		B=P+Q;
		for(ll a=X;a<X+Y;a++)
			for(ll b=P;b<P+Q;b++)Solve(A,B,b-a,a,b);
		if(ans==-1)puts("infinity");
		else cout<<ans<<endl;
	}
	return 0;
}