#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 13;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int k, n, a, b;
bool check(long long d) {
  if (d > n || d * a + (n - d) * b >= k) return false;
  return true;
}
int BS(int l, int r) {
  while (r - l >= 5) {
    int mid = (l + r) / 2;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cin >> k >> n >> a >> b;
    bool fl = false;
    int R = BS(0, n + 1);
    for (int i = R; i >= R - 6 && i >= 0; --i)
      if (check(i)) {
        cout << i << endl;
        fl = true;
        break;
      }
    if (!check(0)) cout << -1 << endl;
  }
}
