#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  vector<long long> a;
  while (t--) {
    long long k, n, a, b;
    cin >> k >> n >> a >> b;
    long long s = 0, e = n;
    long long ans = -1;
    while (s <= e) {
      bool h = true;
      long long mid = (s + e) / 2;
      long long temp = k;
      k -= mid * a;
      if (k <= 0) {
        h = false;
      }
      if (k % b == 0) {
        if (mid + k / b - 1 < n) h = false;
      } else if (mid + k / b < n)
        h = false;
      if (h == true) {
        ans = mid;
        s = mid + 1;
      } else
        e = mid - 1;
      k = temp;
    }
    cout << ans << endl;
  }
}
