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