#include <bits/stdc++.h>
using namespace std;
set<long long>::iterator it;
multiset<long long>::iterator itr;
bool valid(string x) {
  long long sum = 0;
  for (long long i = 0; i < x.length(); i++) {
    sum = sum + x[i] - '0';
  }
  if (sum % 4 == 0)
    return true;
  else
    return false;
}
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 = min((rr - 1) / (a - b), n);
    }
    cout << ans << endl;
  }
}
