#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long k, n, a, b;
  cin >> k >> n >> a >> b;
  long long check = n * a;
  if (k - 1 >= check) {
    cout << n << endl;
  } else {
    k--;
    long long c = k - (b * n);
    double y = c / (a - b);
    long long x = floor(y);
    if (x < 0 || c < 0) {
      cout << -1 << endl;
    } else {
      cout << x << endl;
    }
  }
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    solve();
  }
}
