#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  cin >> T;
  for (long long t = 0; t < (long long)T; t++) {
    long long x, y, a, b;
    cin >> x >> y >> a >> b;
    b = -b;
    if (a == b) {
      if (x != y)
        cout << -1 << "\n";
      else
        cout << 0 << "\n";
    } else {
      if ((y - x) % (a - b) != 0) {
        cout << -1 << "\n";
      } else {
        long long ans = (y - x) / (a - b);
        if (ans < 0)
          cout << -1 << "\n";
        else
          cout << ans << "\n";
      }
    }
  }
  return 0;
}
