#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long n) {
  a %= 1000000007;
  if (n == 1) return a;
  if (n == 0) return 1;
  if (n % 2) return a * power(a * a, n / 2);
  return power(a * a, n / 2);
}
const long long md = 998244353;
const long long inf = (long long)1e18;
bool check(long long x, long long k, long long a, long long b, long long n) {
  if (x * a >= k) return 0;
  if (x >= n) return 1;
  k -= x * a;
  if ((n - x) * b >= k) return 0;
  return 1;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long k, n, a, b;
    cin >> k >> n >> a >> b;
    if (k / b < n || k % b == 0 && k / b <= n) {
      cout << -1 << "\n";
      continue;
    }
    long long lo = 0, hi = k;
    while (lo < hi) {
      long long mid = (lo + hi + 1) / 2;
      if (check(mid, k, a, b, n))
        lo = mid;
      else
        hi = mid - 1;
    }
    if (check(lo, k, a, b, n))
      cout << min(lo, n) << "\n";
    else
      cout << -1 << "\n";
  }
  return 0;
}
