#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
#define all(v) v.begin(), v.end()
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, b) for (ll i = a; i < b; ++i)
#define rep_down(i, a, b) for (ll i = a; i > b; --i)

#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second

#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>

#define vvvvdo vector<vector<vector<vector<double>>>>
#define vvvdo vector<vector<vector<double>>>
#define vvdo vector<vector<double>>
#define vdo vector<double>

#define maze(S, H, W) vector<vector<char>> S(H, vector<char>(W))

#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
// constexpr ll mod = 998244353;
constexpr ll mod = 67280421310721;
// constexpr ll mod = 1e18+3;
// ll mod = 1000000007;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a >= b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt(T val) {
    cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
template <typename T>
void pt_vvll(vector<vector<T>> &v) {
    ll vs = v.size();
    rep(i, vs) pt_vll(v[i]);
}

template <typename X, typename Y>
void pt_pair(pair<X, Y> val) {
    cout << val.fi << " " << val.se << "\n";
}

template <typename X, typename Y>
void pt_vpair(vector<pair<X, Y>> &v) {
    rep(i, v.size()) pt_pair(v[i]);
}

ll gcd(ll a, ll b) {
    if (a % b == 0) return b;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll x, ll n) {
    ll ret = 1;
    if (x < 0) return 0ll;
    while (n > 0) {
        if (n & 1) ret = ret * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return ret;
}
ll minv(ll a, ll m) { return modpow(a, m - 2); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll t;
    cin >> t;
    while (t--) {
        ll N;
        cin >> N;
        string s1, s2, s3;
        cin >> s1 >> s2 >> s3;
        string ans;
        rep(i, N) ans.push_back('1');
        rep(i, N) ans.push_back('0');
        ans.push_back('1');
        pt(ans);
    }
    return 0;
}
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

// 負の数にも対応した mod
// 例えば -17 を 5 で割った余りは本当は 3 (-17 ≡ 3 (mod. 5))
// しかし単に -17 % 5 では -2 になってしまう
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 拡張 Euclid の互除法
// ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
long long extGcd(long long a, long long b, long long &p, long long &q) {  
    if (b == 0) { p = 1; q = 0; return a; }  
    long long d = extGcd(b, a%b, q, p);  
    q -= a/b * p;  
    return d;  
}

// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
  long long p, q;
  long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
  if ((b2 - b1) % d != 0) return make_pair(0, -1);
  long long m = m1 * (m2/d); // lcm of (m1, m2)
  long long tmp = (b2 - b1) / d * p % (m2/d);
  long long r = mod(b1 + m1 * tmp, m);
  return make_pair(r, m);
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T; cin >> T;
    while(T--){
        ll X, Y, P, Q; cin >> X >> Y >> P >> Q;
        ll ans = LLINF;
        //(2X+2Y)n + X <= t <= (2X+2Y)n + X + Y - 1 &&
        //(P+Q)n + P <= t <= (P+Q)(n+1) - 1
        for(ll alpha = X; alpha <= X+Y-1; alpha++){
            for(ll beta = P; beta <= P+Q-1; beta++){
                pair<ll, ll> temp = ChineseRem(alpha, X*2 + Y*2, beta, P+Q);
                if(temp != pair<ll, ll>(0, -1)) ans = min(ans, temp.first);
            }
        }
        if(ans == LLINF) cout << "infinity" << endl;
        else cout << ans << endl;
    }
    return 0;
}