#include <bits/stdc++.h>
using namespace std;
const int size = 1e5 + 7;
const int maxm = 2e9 + 7;
long long p, q, x, y;
bool check(int mid) {
  return (p * mid - x >= 0 && q * mid - y >= 0 && (q - p) * mid - (y - x) >= 0);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  long long l, r, mid;
  cin >> t;
  while (t--) {
    cin >> x >> y >> p >> q;
    l = 0, r = 2e9;
    while (l < r) {
      mid = l + r >> 1;
      if (check(mid))
        r = mid;
      else
        l = mid + 1;
    }
    if (r == 2e9)
      cout << -1 << endl;
    else
      cout << q * r - y << endl;
  }
  return 0;
}
