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