#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int q, k, n, a, b;
bool check(int mid) {
  int s = 0;
  s += mid;
  int kk = k - mid * b;
  s += (kk) / a;
  if (kk % a == 0) s--;
  return s >= n;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> q;
  while (q--) {
    cin >> k >> n >> a >> b;
    int cnt = k / b;
    if (k % b == 0) cnt--;
    if (cnt < n)
      cout << -1 << endl;
    else {
      int l = 0, r = (k / b), mid;
      int ans;
      if (k % b == 0) r--;
      while (l <= r) {
        mid = (l + r) / 2;
        if (check(mid)) {
          ans = (k - (mid * b)) / a;
          if ((k - (mid * b)) % a == 0) ans--;
          r = mid - 1;
        } else
          l = mid + 1;
      }
      if (ans > n) ans = n;
      cout << ans << endl;
    }
  }
  return 0;
}
