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