#include <bits/stdc++.h>
using namespace std;
const int N = 0;
long long k, n, b, a;
bool can(int x) {
  if ((k - (a * x + b * (n - x)) > 0)) return true;
  return false;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> k >> n >> a >> b;
    long long res = k - b * n;
    if (res <= 0)
      cout << -1 << '\n';
    else {
      cout << min(n, (res - 1) / (a - b)) << '\n';
    }
  }
}
