#include <bits/stdc++.h>
using namespace std;
bool check(long long int k, long long int n, long long int a, long long int b,
           long long int val) {
  long long int tot = 0;
  k -= a * val;
  if (k < 0) return false;
  if (k == 0) {
    return false;
  }
  tot += val;
  tot += k / b;
  k = k % b;
  if (k == 0) tot--;
  if (tot >= n) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int k, n, a, b;
    cin >> k >> n >> a >> b;
    long long int ans = -1;
    long long int l = 0, r = 1e9 + 10;
    while (l <= r) {
      long long int mid = (l + r) / 2;
      if (check(k, n, a, b, mid)) {
        ans = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    if (ans == -1)
      cout << ans << '\n';
    else
      cout << min(ans, n) << '\n';
  }
  return 0;
}
