#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = (long long)(998244353)) {
  return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = (long long)(998244353)) {
  return (a % p + b % p) % p;
}
long long fpow(long long n, long long k, long long p = (long long)(998244353)) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
long long inv(long long a, long long p = (long long)(998244353)) {
  return fpow(a, p - 2, p);
}
bool sa(const pair<long long, long long> &a,
        const pair<long long, long long> &b) {
  return (a.second < b.second);
}
bool fd(const pair<long long, long long> &a,
        const pair<long long, long long> &b) {
  return (a.first > b.first);
}
bool sd(const pair<long long, long long> &a,
        const pair<long long, long long> &b) {
  return (a.second > b.second);
}
long long dx[4] = {0, 0, 1, -1};
long long dy[4] = {1, -1, 0, 0};
bool valid(long long x, long long y, long long n, long long m) {
  if (x < 0 || y < 0) {
    return false;
  } else if (x >= n || y >= m) {
    return false;
  } else
    return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long k, n, a, b, lo, hi, ans;
    cin >> k >> n >> a >> b;
    lo = 0;
    hi = n;
    ans = -1;
    while (lo <= hi) {
      long long mid = (lo + hi) / 2;
      long long rem = k - (a * mid);
      rem -= (n - mid) * b;
      if (rem > 0) {
        lo = mid + 1;
        ans = max(ans, mid);
      } else {
        hi = mid - 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
