#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &X) {
  X = 0;
  char ch = 0;
  T op = 1;
  for (; ch > '9' || ch < '0'; ch = getchar())
    if (ch == '-') op = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    X = (X << 3) + (X << 1) + ch - 48;
  X *= op;
}
const long long INF = 0x3f3f3f3f;
const long long N = 1e5 + 5;
long long k, n, a, b;
bool judge(long long x) {
  long long y;
  long long test = k;
  test -= x * a;
  long long turn = 0;
  turn += (test - b) / b;
  test -= turn * b;
  if (test > b) {
    test -= b;
    turn++;
  }
  return turn + x >= n;
}
int main() {
  long long q;
  read(q);
  while (q--) {
    read(k);
    read(n);
    read(a);
    read(b);
    long long test = k;
    long long turn = 0;
    turn += (test - b) / b;
    test -= turn * b;
    if (test > b) {
      test -= b;
      turn++;
    }
    if (turn < n) {
      cout << -1 << "\n";
      continue;
    }
    test = k;
    turn += (test - a) / a;
    test -= turn * b;
    if (test > a) {
      test -= a;
      turn++;
    }
    long long l = 0, r = min(turn, n);
    long long ans = 0;
    while (l <= r) {
      long long mid = l + r >> 1;
      if (judge(mid))
        ans = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    cout << ans << "\n";
  }
  return 0;
}
