#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  while (true) {
    int q;
    long long k, n, a, b;
    cin >> q;
    for (int i = 1; i <= q; i++) {
      cin >> k >> n >> a >> b;
      if (n * b >= k) {
        cout << -1 << endl;
      } else {
        long long dif = k - n * b - 1;
        long long unit = a - b;
        cout << min(n, dif / unit) << endl;
      }
    }
    if (!false) {
      break;
    }
  }
  return 0;
}
