#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }
ll inv(ll a, ll m) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }

ll garner(vector<ll> r, vector<ll> m) {
  ll N = r.size();
  ll prod = 1, res = 0, rem = 0;
  rep(i,N) {
    ll g = gcd(prod,m[i]);
    if (abs(r[i]-res)%g) { return -1; }
    rem = res%g; prod /= g; m[i] /= g; res /= g; r[i] /= g;
    ll t = ((r[i]-res)*inv(prod,m[i])%m[i]+m[i])%m[i];
    res = (res+t*prod)*g + rem;
    prod *= m[i] * g;
  }
  return res;
}

int main() {
  ll T; cin >> T;
  rep(_,T) {
    ll X, Y, P, Q; cin >> X >> Y >> P >> Q;
    ll m1 = 2*(X+Y), m2 = P+Q;
    ll result = LLINF;
    repr(i,X,X+Y) repr(j,P,P+Q) {
      ll res = garner({i,j},{m1,m2});
      if (res!=-1) result = min(result,res);
    }
    if (result==LLINF) cout << "infinity" << endl;
    else cout << result << endl;
  }
  return 0;
}
// R SAI KRISHNA 
#include <bits/stdc++.h>
#define for0(i, n) for (int i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (ll)(n); ++i)
#define forc(i, l, r) for (int i = (ll)(l); i <= (ll)(r); ++i)
#define forr0(i, n) for (int i = (ll)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (ll)(n); i >= 1; --i)
#define pb push_back
#define fi first  
#define debug(x) cout << #x << " -> " << x << endl;
#define endl '\n'
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) ll((a).size())
#define mod 1000000007
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld; 

void debug_vec(vector<ll>&v){  
    cout << '[';
    for(auto i:v)cout << i << ", "; cout << "]";
    cout << "\n";
}   

void debug_set(set<ll>&st){  
    cout << "{";
    for(auto i:st)cout << i << ", ";
    cout << "}";
    cout << "\n";
} 


void fast()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
} 

bool prime[1000001];
void sieve()
{
  memset(prime, true, sizeof(prime));
  prime[1]=false;
  for (int p=2; p*p<=1000000; p++)
  {
    if (prime[p] == true)
    {
        for (int i=p*p; i<=1000000; i += p)
                prime[i] = false;
    }
  }
} 

void print(bool f){ 
    if(f)cout << "YES\n"; 
    else cout << "NO\n";
}  

void google(int x){  
    cout << "Case #" << x << ": " ;
} 

void solve()
{
    ll n; 
    cin >> n;  
    ll temp = 6; 
    set<ll>st; 
    st.insert(6); 
    st.insert(10); 
    st.insert(15);
    while(st.size() < n && temp < 10000){ 
        
        temp += 6;  
        if(temp <= 10000)
        st.insert(temp);
    }  
    temp = 10; 
    while(st.size()<n && temp<10000){ 
        temp += 10;  
        if(temp <= 10000)
        st.insert(temp);
    } 
    temp = 15; 
    while(st.size() < n && temp<10000){ 
        temp += 15;  
        if(temp <= 10000)
        st.insert(temp);
    } 
    for(auto i:st)cout << i << ' '; 
    cout << endl;
    
} 

int main()
{
  fast();
  /*ll t;
  cin >> t;
  for(int tt = 1;tt <= t ;tt++)*/
  solve();

return 0;
}
