#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long n, k, x, y, ans;
    cin >> n >> k >> x >> y;
    if (k * y > n - 1) {
      cout << "-1" << endl;
      continue;
    }
    if ((n - k * y) % (x - y) == 0)
      ans = min(k, (n - (k * y)) / (x - y) - 1);
    else
      ans = min(k, (n - (k * y)) / (x - y));
    cout << ans << endl;
  }
  return 0;
}
