#include <bits/stdc++.h>
using namespace std;
long long a, b, p, q, t;
bool check(long long mid) {
  return mid * b - q >= mid * a - p && mid * a - p >= 0;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld%lld%lld", &p, &q, &a, &b);
    long long l = 0, r = 2e9;
    while (l < r) {
      long long mid = (l + r) / 2;
      if (check(mid))
        r = mid;
      else
        l = mid + 1;
    }
    if (l >= 2e9)
      printf("-1\n");
    else
      printf("%lld\n", l * b - q);
  }
  return 0;
}
