#include <bits/stdc++.h>
using namespace std;
int main() {
  long long q;
  cin >> q;
  long long k, n, a, b;
  while (q--) {
    cin >> k >> n >> a >> b;
    long long low = 0, high = n;
    long long ans = -1;
    while (low <= high) {
      long long mid = low + (high - low) / 2;
      long long final = k - mid * a - (n - mid) * b;
      if (final > 0) {
        low = mid + 1;
        ans = mid;
      } else {
        high = mid - 1;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
