#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e6 + 7;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const unsigned long long p = 67;
const unsigned long long MOD = 1610612741;
long long n, k, a, b;
int m;
bool check(long long mid) {
  long long leftBattary = n - mid * a;
  if (leftBattary < 0) return false;
  long long bTimes = leftBattary / b;
  long long remainBattary = leftBattary % b;
  if (mid + bTimes < k) {
    return false;
  } else if (mid + bTimes > k) {
    return true;
  } else {
    return remainBattary > 0;
  }
}
long long binarySearch(long long _high) {
  long long low = 0;
  long long high = _high;
  long long ans = 0;
  while (low <= high) {
    long long mid = (low + high) / 2;
    if (check(mid)) {
      ans = mid;
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  return ans;
}
int main() {
  scanf("%d", &m);
  while (m--) {
    scanf("%I64d %I64d %I64d %I64d", &n, &k, &a, &b);
    int maxtime = n / b;
    int leftBattary = n % b;
    if ((maxtime == k && leftBattary > 0) || maxtime > k) {
      printf("%I64d\n", min(binarySearch(maxtime), k));
    } else {
      printf("-1\n");
    }
  }
  return 0;
}
