#include <iostream>
using namespace std;

int main() {
	long long a, b, c, d;
	//long long n, x, y;
	long long ans = 0;
	double n = 0;
	cin >> a >> b >> c >> d;
	if (b >= d*c) {
	    ans = -1;
	} else {
	   // n = 0;
	   // x = 0;
	   // y = 0;
	   // while (a + x > d*y) {
	   //     x += b;
	   //     y += c;
	   //     n++;
	   // }
	   n = (double)a/(double)(c*d - b);
	   ans = (long long)n;
	   if (n - ans != 0) {
	       ans++;
	   }
	}
	cout << ans << '\n';
	return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define MP make_pair
#define PB push_back
#define REP(i, L, R) for (int i = L; i < (R); ++i)
#define SZ(x) (int)x.size()

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

template <typename T>
bool ckmin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
bool ckmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}

// O(log max(a,b))
template <typename T = int>
T gcd(T a, T b) {
  if (b == 0) {
    return a;
  }
  return gcd<T>(b, a % b);
}

// Finds gcd(a,b) and x, y s.t. ax + by = gcd(a,b).
template <typename T = int>
T ext_gcd(T a, T b, T &x, T &y) {
  T d = a;
  if (b != 0) {
    d = ext_gcd<T>(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    // b = 0 then gcd(a,b) = a = a*1 + b*0
    x = 1;
    y = 0;
  }

  return d;
}

// Finds x s.t. ax = 1 (mod m) given (a,m)=1.
// (a,m)=1=ax+my.
template <typename T = int>
T mod_inverse(T a, T m) {
  T x, y;
  ext_gcd<T>(a, m, x, y);
  return (m + x % m) % m;
}

// Computes C(n,k) % m.
template <typename T = int>
T comb(T n, T k, T m) {
  if (n < k || k < 0 || n < 0) return 0;
  T ret = 1;
  for (T i = 0; i < k; ++i) {
    ret = ret * (n - i) % m;
    ret = ret * mod_inverse<T>(i + 1, m) % m;
  }

  return ret;
}

// Solves for x in ax = b (mod m). The solution when exists is of the form x
// (mod n). Returns false if no solution exists, in which case x and n are
// undefined.
template <typename T = int>
bool solve_lineq(T a, T b, T m, T &x, T &n) {
  T d = gcd<T>(a, m);
  if (b % d != 0) {
    return false;
  }

  // ax - b = tm -> a/d x - b/d = t m/d -> a' x = b' (mod m') with (a',m') = 1.
  // The solution is x = inverse(a') b' (mod m').
  a /= d;
  b /= d;
  m /= d;
  x = mod_inverse(a, m) * b % m;
  n = m;

  return true;
}

// Solves a linear system: A_i x = B_i (mod M_i) for i=1,...n (n >= 1).
// Returns a pair (b, m) means x=b(mod m) is the solution. The pair (0, -1)
// means no solution existed.
template <typename T = int>
pair<T, T> solve_linsys(const vector<T> &A, const vector<T> &B,
                        const vector<T> &M) {
  // Consider the first equation x = 0 (mod 1).
  T x = 0, m = 1;

  for (int i = 0; i < A.size(); ++i) {
    // x = b (mod m) -> x = b+tm
    // A[i] x = B[i] (mod M[i]) -> (A[i]*m) * t = (B[i]-A[i]*b) (mod M[i])
    T a = A[i] * m;
    T b = B[i] - A[i] * x;
    T d = gcd(M[i], a);
    if (b % d != 0) {
      // no solution
      return make_pair(0, -1);
    }
    T t = b / d * mod_inverse(a / d, M[i] / d) % (M[i] / d);
    x = x + m * t;
    m *= M[i] / d;
  }
  return make_pair((x + m) % m, m);
}

void solve() {
  int t;
  cin >> t;
  REP(ti, 0, t) {
    ll X, Y, P, Q;
    cin >> X >> Y >> P >> Q;

    ll ans = -1;
    REP(q, 0, Q) {
      REP(y, 0, Y) {
        // solve: x = P+q (mod P+Q) and x = X+y (mod 2X+2Y)
        pl sol = solve_linsys<ll>(vector<ll>{1, 1}, vector<ll>{P + q, X + y},
                                  vector<ll>{P + Q, 2 * X + 2 * Y});
        if (sol.second != -1) {
          if (ans == -1) {
            ans = sol.first;
          } else {
            ans = min(ans, sol.first);
          }
        }
      }
    }

    if (ans == -1) {
      cout << "infinity";
    } else {
      cout << ans;
    }
    cout << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
