#include <bits/stdc++.h>
using namespace std;
long long int recpow(long long int x, long long int n) {
  long long int temp;
  if (n == 0)
    return 1;
  else if (n % 2 == 0) {
    temp = recpow(x, n / 2) % 1000000007;
    return (temp * temp) % 1000000007;
  } else {
    temp = recpow(x * x, (n - 1) / 2) % 1000000007;
    return (x % 1000000007 * (temp * temp) % 1000000007) % 1000000007;
  }
}
void extendedEuclid(long long int A, long long int B);
long long int d, x, y;
long long int modInverse(long long int A, long long int M) {
  extendedEuclid(A, M);
  return (x % M + M) % M;
}
void extendedEuclid(long long int A, long long int B) {
  if (B == 0) {
    d = A;
    x = 1;
    y = 0;
  } else {
    extendedEuclid(B, A % B);
    int temp = x;
    x = y;
    y = temp - (A / B) * y;
  }
}
int mincom(int b1, int a1, int b2, int a2) {
  if (b1 != b2 && a1 == a2)
    return max(b1, b2) + a1;
  else {
    int i = 0, j = 0;
    while (1) {
      if (b1 + a1 * i == b2 + a2 * j) {
        break;
      } else if (b1 + a1 * i > b2 + a2 * j)
        j++;
      else
        i++;
    }
    return b1 + a1 * i;
  }
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    long long int k, n, a, b;
    cin >> k >> n >> a >> b;
    long long int r, d, f;
    d = a - b;
    f = k - 1 - n * b;
    if (f < 0)
      r = -1;
    else
      r = f / d;
    if (r > n) r = n;
    cout << r << endl;
  }
  return 0;
}
