#include <bits/stdc++.h>
using namespace std;
int y, x, n, com, ans, k, q, cur, a, b;
map<int, int> m;
int main() {
  cin >> q;
  while (q--) {
    cin >> n >> k >> a >> b;
    n--;
    int mid, l = 0, r = n / a + 1;
    while (r - l > 1) {
      mid = (l + r) / 2;
      x = mid;
      y = (n - mid * a);
      x += y / b;
      if (x >= k)
        l = mid;
      else
        r = mid;
    }
    x = l;
    y = (n - l * a);
    x += y / b;
    if (x >= k)
      cout << min(l, k) << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
