#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
long long my_floor(long long a, long long b) {
  return a % b == 0 ? a / b - 1 : a / b;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long k, n, a, b;
    cin >> k >> n >> a >> b;
    if (k - b * n <= 0)
      cout << -1 << endl;
    else
      cout << min(my_floor(k - b * n, a - b), n) << endl;
  }
  return 0;
}
