#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    long long int K, N, a, b;
    cin >> K >> N >> a >> b;
    long long int l = 1, r = N;
    if ((K + a - 1) / a > N) {
      cout << min((K + a - 1) / a, N) << endl;
    } else if ((K + b - 1) / b > N) {
      long long int ans = l, t, d;
      while (l <= r) {
        long long int mid = (l + r) / 2;
        t = K - b * mid;
        d = (t + a - 1) / a;
        if (d > N - mid) {
          ans = mid;
          r = mid - 1;
        } else {
          l = mid + 1;
        }
      }
      cout << N - ans << endl;
    } else {
      cout << -1 << endl;
    }
  }
}
