#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int q;
  cin >> q;
  while (q--) {
    long long int k, n, a, b;
    cin >> k >> n >> a >> b;
    if (k <= b * n) {
      cout << "-1";
    } else {
      long long int ans = (k - b * n) % (a - b) ? (k - b * n) / (a - b)
                                                : (k - b * n) / (a - b) - 1;
      cout << min(ans, n);
    }
    cout << "\n";
  }
}
