#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long q;
  cin >> q;
  while (q--) {
    long long k, n, a, b;
    cin >> k >> n >> a >> b;
    if (k <= (n * b))
      cout << "-1" << endl;
    else {
      cout << min(n, (k - (n * b) - 1) / (a - b)) << endl;
    }
  }
  return 0;
}
