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