#include <bits/stdc++.h>
using namespace std;
void binary_search(long long int k, long long int n, long long int n_l,
                   long long int n_r, long long int a, long long int b,
                   long long int& curr_result) {
  if (n_l >= n_r) return;
  long long int middle = n_l + (n_r - n_l) / 2;
  long long int value = middle * a + b * (n - middle);
  if (value < k) {
    if (value > curr_result) curr_result = middle;
    binary_search(k, n, middle + 1, n_r, a, b, curr_result);
  } else
    binary_search(k, n, n_l, middle, a, b, curr_result);
}
int main(void) {
  int T = 0;
  cin >> T;
  while (T--) {
    long long int k, n, a, b;
    cin >> k >> n >> a >> b;
    long long int answer = -1;
    binary_search(k, n, 0, n + 1, a, b, answer);
    cout << answer << endl;
  }
  return 0;
}
