#include <bits/stdc++.h>
const int MAX_LEN = 1010;
using namespace std;
template <typename U, typename V>
string to_string(pair<U, V>);
string to_string(const string& e_) { return "\"" + e_ + "\""; }
string to_string(char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string(bool e_) { return e_ ? "true" : "false"; }
template <typename T>
string to_string(T e_) {
  string s_ = "[ ";
  for (const auto& x_ : e_) s_ += to_string(x_) + " ";
  return s_ + "]";
}
template <typename U, typename V>
string to_string(pair<U, V> e_) {
  return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str() { ; }
template <typename U, typename... V>
void dbg_str(U u, V... v) {
  ;
  dbg_str(v...);
}
long long int t, x, y, p, q;
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%lld %lld %lld %lld", &x, &y, &p, &q);
    long long int lt = 0;
    long long int rt = 1e9;
    long long int ans = -1;
    long long int mt;
    while (lt <= rt) {
      ;
      mt = (lt + rt) / 2;
      if (mt * p >= x && mt * (q - p) >= (y - x)) {
        ans = mt;
        rt = mt - 1;
      } else
        lt = mt + 1;
    };
    if (ans == -1)
      printf("-1\n");
    else
      printf("%lld\n", q * ans - y);
  }
}
