#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int q;
  cin >> q;
  while (q--) {
    long long int k, n, a, b, up, down;
    cin >> k >> n >> a >> b;
    if (n * b >= k)
      cout << "-1\n";
    else if (a == b)
      cout << n << "\n";
    else {
      up = k - (b * n);
      down = a - b;
      if (up % down != 0 && (up / down) < n)
        cout << up / down << "\n";
      else if (up % down != 0 && (up / down) >= n)
        cout << n << "\n";
      else if (up % down == 0 && (up / down) - 1 < n)
        cout << (up / down) - 1 << "\n";
      else if (up % down == 0 && (up / down) - 1 >= n)
        cout << n << "\n";
    }
  }
  return 0;
}
