#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
  scanf("%lld", &a);
  for (i = 1; i <= a; i++) {
    scanf("%lld %lld %lld %lld", &b, &c, &d, &e);
    f = 0;
    g = (2e18) / e;
    while (f <= g) {
      h = (f + g) / 2;
      m = d * h;
      n = e * h;
      if (n >= c && m >= b && n - c >= m - b)
        g = h - 1;
      else
        f = h + 1;
    }
    if (f >= (2e18) / e)
      printf("-1\n");
    else
      printf("%lld\n", max(f * e - c, 0LL));
  }
  return 0;
}
