#include <bits/stdc++.h>
using namespace std;
long long q, k, n, a, b, flag;
int main() {
  cin >> q;
  for (long long i = 1; i <= q; i++) {
    cin >> k >> n >> a >> b;
    flag = 0;
    if (b * n >= k)
      flag--;
    else if (a * n < k)
      flag = n;
    else {
      long long l = 1, r = n - 1, mid;
      while (l <= r) {
        mid = (r + l) / 2;
        if (a * mid + b * (n - mid) >= k)
          r = mid - 1;
        else
          l = mid + 1;
        flag = r;
      }
    }
    cout << flag << endl;
  }
}
