#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3ffffffffffff;
int main() {
  long long T;
  scanf("%lld", &T);
  while (T--) {
    long long k, n, a, b;
    scanf("%lld%lld%lld%lld", &k, &n, &a, &b);
    k -= b * n;
    if (k <= 0)
      printf("-1\n");
    else
      printf("%lld\n", min(n, (k - 1) / (a - b)));
  }
}
