#include <bits/stdc++.h>
using namespace std;
long long x, y, p, q;
long long bin(long long lo, long long hi) {
  long long ans = -1;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    if ((mid * p >= x) && (mid * q >= y) && (mid * p - x <= mid * q - y)) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return ans;
}
int main() {
  int TC;
  cin >> TC;
  while (TC--) {
    cin >> x >> y >> p >> q;
    long long fin = bin(0, 10000000000);
    if (fin < 0)
      cout << fin << endl;
    else
      cout << (fin * q) - y << endl;
  }
}
