#include <bits/stdc++.h>
using namespace std;
bool ispossible(long long int k, long long int n, long long int a,
                long long int b, long long int mid) {
  if ((mid * a + (n - mid) * b) < k) {
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int k, n, a, b;
    cin >> k >> n >> a >> b;
    long long int low = 0;
    long long int high = n;
    long long int ans = -1;
    while (low <= high) {
      long long int mid = low + (high - low) / 2;
      if (ispossible(k, n, a, b, mid)) {
        if (mid > ans) {
          ans = mid;
        }
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
