#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 1;
int n, N, k, a, b;
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d %d %d", &k, &n, &a, &b);
    int div = k / a;
    int rem = k % a;
    if (!rem) div--, rem += a;
    int res = -1;
    long long l = 0, r = div;
    while (l <= r) {
      long long j = l + r >> 1;
      long long A = j;
      long long B = n - j;
      long long x = A * a;
      long long y = B * b;
      if (x + y < k) {
        l = j + 1;
        res = j;
      } else
        r = j - 1;
    }
    printf("%d\n", res > n ? n : res);
  }
}
