#include <bits/stdc++.h>
using namespace std;
void debugger13524() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
bool isValid(long long int x, long long int n, long long int a, long long int b,
             long long int k) {
  if ((a * x + b * (n - x)) < k) {
    return true;
  } else {
    return false;
  }
}
void solve() {
  long long int k, n, a, b;
  cin >> k >> n >> a >> b;
  int l = -1, r = n + 1;
  while (r - l > 1) {
    int m = l + (r - l) / 2;
    if (isValid(m, n, a, b, k)) {
      l = m;
    } else {
      r = m;
    }
  }
  cout << l << "\n";
}
int32_t main() {
  debugger13524();
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) solve();
  return 0;
}
