#include <bits/stdc++.h>
using namespace std;
int main() {
  long long q;
  while (cin >> q) {
    while (q) {
      long long n, k, a, b;
      cin >> k >> n >> a >> b;
      long long l = -1, h = n;
      bool gt = false;
      while (l < h) {
        long long mid = (l + h + 1) / 2;
        long long p = mid * a;
        bool ys = false;
        if (p < k) {
          long long q = (k - p) / b;
          if ((k - p) % b == 0) {
            q--;
          }
          if (mid + q >= n) {
            gt = true;
            ys = true;
          }
        }
        if (ys) {
          l = mid;
        } else {
          h = mid - 1;
        }
      }
      if (gt) {
        cout << l << endl;
      } else {
        puts("-1");
      }
      q--;
    }
  }
}
