#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long k, n, a, b, c = 0;
    cin >> k >> n >> a >> b;
    long long l = 0, r = n, m;
    while (l <= r) {
      m = (l + r) / 2;
      if (m * a + b * (n - m) - k >= 0)
        r = m - 1;
      else
        l = m + 1;
    }
    cout << r << endl;
  }
  return 0;
}
