#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int q;
  cin >> q;
  while (q--) {
    long long int k, n, a, b;
    cin >> k >> n >> a >> b;
    long long int l = 0, r = n;
    long long int ans = 0;
    long long int left;
    while (l <= r) {
      long long int mid = (l + r) / 2;
      long long int step = n - mid;
      long long int rem = k - mid * a;
      left = rem - step * b;
      if (left > 0) {
        l = mid + 1;
        ans = mid;
      } else
        r = mid - 1;
      if (mid == 0) {
        if (left <= 0) ans = -1;
      }
    }
    cout << ans << endl;
  }
}
