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