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