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