#include <bits/stdc++.h>
const long long INF = 10e15;
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    long long k, n, a, b;
    cin >> k >> n >> a >> b;
    k--;
    if (k - b * n < 0) {
      cout << -1 << endl;
      continue;
    }
    if (k - a * n >= 0) {
      cout << n << endl;
    } else {
      long long p = 0, q = n;
      while (p != q) {
        long long mid = (p + q) / 2;
        if (k - mid * a - (n - mid) * b >= 0) {
          p = mid;
        } else {
          q = mid - 1;
        }
        if (q == p + 1) {
          if (k - q * a - (n - q) * b >= 0) {
            p = q;
          }
          break;
        }
      }
      cout << p << endl;
    }
  }
  return 0;
}
