#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }
const int MAXN = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
int q;
int k, n, a, b;
int main() {
  scanf("%d", &q);
  for (int h = 0; h < q; h++) {
    scanf("%d%d", &k, &n);
    scanf("%d%d", &a, &b);
    if (k / b < n) {
      cout << "-1" << endl;
      continue;
    }
    if (b * n == k) {
      cout << -1 << endl;
      continue;
    }
    int num = k - b * n - 1;
    int dif = a - b;
    int x = num / dif;
    cout << min(x, n) << endl;
  }
  return 0;
}
