#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
const int mo = 998244353;
void sol() {
  int k, n, a, b;
  scanf("%d%d%d%d", &k, &n, &a, &b);
  --k;
  printf("%d\n", k / b < n ? -1 : min((k - b * n) / (a - b), n));
}
int main() {
  int t;
  scanf("%d", &t);
  for (auto i = (1); i <= (t); ++i) sol();
}
