#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long k, n, a, b;
  cin >> k >> n >> a >> b;
  long long l = 0, r = n;
  while (l + 1 < r) {
    long long x = (l + r) / 2;
    long long y = n - x;
    if (x < (k - b * y + a - 1) / a) {
      l = x;
    } else {
      r = x;
    }
  }
  if (l * a + b * (n - l) >= k) {
    cout << -1 << '\n';
  } else {
    if (r * a + b * (n - r) < k) {
      cout << r << '\n';
    } else {
      cout << l << '\n';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
