#include <bits/stdc++.h>
using namespace std;
static long long int mod = (long long)(1e9) + 7;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
vector<int> prime((long long)(1e7), 1);
void seive(long long n) {
  long long i, j;
  prime[0] = prime[1] = 0;
  for (i = 2; i * i <= n; i++) {
    if (prime[i] == 1) {
      for (j = i * i; j <= n; j += i) prime[j] = 0;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t, n, i, j, q, d;
  string str;
  char ch[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
               'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  cin >> t;
  while (t--) {
    long long k, a, b;
    cin >> k >> n >> a >> b;
    d = (k / b);
    if (k % b == 0) d--;
    if (d < n) {
      cout << "-1\n";
      continue;
    }
    long long l = 0, r = n, ans = 0;
    while (l <= r) {
      long long mid = (l + r) / 2;
      if (mid * a < k) {
        long long v = k - mid * a;
        long long v1 = (v / b);
        if (v % b == 0) v1--;
        if (v1 + mid >= n) {
          ans = mid;
          l = mid + 1;
        } else {
          r = mid - 1;
        }
      } else {
        r = mid - 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
