#include <bits/stdc++.h>
using namespace std;
long long k, n, a, b, res;
bool check(int x) {
  if (a * x < k && 0 < k - a * x && k - a * x < a) {
    if (x >= n)
      return 1;
    else if (x + (k - a * x - 1) / b >= n)
      return 1;
    else
      return 0;
  }
  long long y = (k - a * x - 1) / b;
  return (y >= 0 && a * x + b * y < k && x + y >= n);
}
void solve() {
  res = 0;
  cin >> k >> n >> a >> b;
  long long l = 0, r = 1000000000;
  while (l < r) {
    long long m = (l + r + 1) >> 1;
    if (check(m))
      l = m;
    else
      r = m - 1;
  }
  if (!check(l))
    cout << "-1\n";
  else
    cout << min(l, n) << '\n';
}
int main() {
  if (0) {
    freopen("CP.inp", "r", stdin);
    freopen("CP.out", "w", stdout);
  }
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
