#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)(8e18);
const long long int MOD = 1e9 + 7;
bool possible(long long int p, long long int n, long long int a,
              long long int b, long long int k) {
  if (k > (p * a + (n - p) * b)) return true;
  return false;
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int q;
  cin >> q;
  while (q--) {
    long long int k, n, a, b;
    cin >> k >> n >> a >> b;
    long long int l = 0, r = n;
    long long int ans = -1;
    while (l <= r) {
      int mid = l + (r - l) / 2;
      if (possible(mid, n, a, b, k)) {
        ans = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    cout << ans << '\n';
  }
}
