#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long div_ceil(long long u, long long d) { return (u / d) + !!(u % d); }
void soln();
signed main() {
  long long t = 1;
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  };
  cin >> t;
  while (t--) soln();
  return 0;
}
void soln() {
  long long x, y, p, q;
  cin >> x >> y >> p >> q;
  auto check = [&](long long t) {
    return (p * t >= x) and ((q - p) * t >= (y - x));
  };
  long long lo = 0, hi = y + 1;
  while (lo < hi) {
    long long mid = (lo + hi) / 2;
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  if (check(hi)) {
    cout << q * hi - y << "\n";
  } else {
    cout << -1 << "\n";
  }
}
