#include <bits/stdc++.h>
using namespace std;
int main() {
  long long q, k, n, a, b, A, B, C;
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld%lld%lld%lld", &k, &n, &a, &b);
    A = k - n * b;
    B = a - b;
    C = n;
    if (A % B == 0)
      C = min(C, A / B - 1);
    else
      C = min(C, A / B);
    if (A <= 0)
      C = -1;
    else
      C = max(0LL, C);
    printf("%lld\n", C);
  }
  return 0;
}
