#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
long long t, k, n, a, b, ans;
int cnt(long long x) {
  long long ret, batt = k;
  if (batt <= x * a) return -1;
  batt -= x * a;
  ret = x + batt / b;
  if (batt % b == 0) ret--;
  return ret;
}
int main() {
  cin >> t;
  while (t--) {
    cin >> k >> n >> a >> b;
    ans = -1;
    long long l = 0;
    long long r = INF;
    while (l <= r) {
      long long m = (l + r) / 2;
      long long check = cnt(m);
      if (check >= n) {
        l = m + 1;
        ans = m;
      } else
        r = m - 1;
    }
    cout << min(ans, n) << '\n';
  }
  return 0;
}
