#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long k, n, a, b;
    cin >> k >> n >> a >> b;
    if (k - n * b <= 0) {
      cout << -1 << endl;
      continue;
    }
    if ((k - n * b) % (a - b) == 0) {
      long long p = ((k - n * b) / (a - b)) - 1;
      if (p >= n) {
        cout << n << endl;
        continue;
      } else {
        cout << p << endl;
        continue;
      }
    }
    long long p = (k - n * b) / (a - b);
    if (p >= n) {
      cout << n << endl;
      continue;
    } else {
      cout << p << endl;
      continue;
    }
  }
}
