#include <bits/stdc++.h>
using namespace std;
set<long long>::iterator it;
multiset<long long>::iterator itr;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long k, n, a, b;
    cin >> k >> n >> a >> b;
    long long rr = (k - b * n);
    long long ans = -1;
    if (rr > 0) {
      ans = (rr) / (a - b);
      if (rr % (a - b) == 0) ans--;
    }
    cout << min(ans, n) << endl;
  }
}
