#include <bits/stdc++.h>
using namespace std;
long long k, n, a, b;
long long Binary_Search(long long Dau, long long Cuoi) {
  long long Mid;
  if (Dau == Cuoi && Cuoi == n) return n;
  if (Dau <= Cuoi)
    Mid = Dau + (Cuoi - Dau) / 2;
  else
    return -1;
  if (Mid * a + (n - Mid) * b < k && (Mid + 1) * a + (n - Mid - 1) * b >= k)
    return Mid;
  if (Mid * a + (n - Mid) * b < k)
    return Binary_Search(Mid + 1, Cuoi);
  else
    return Binary_Search(Dau, Mid - 1);
  return -1;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    cin >> k >> n >> a >> b;
    cout << Binary_Search(0, n) << endl;
  }
}
