#include <bits/stdc++.h>
using namespace std;
const long long int N = 100010;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int k, n, a, b;
    cin >> k >> n >> a >> b;
    {
      long long int st = 0, en = n, m, ans = -1;
      while (st <= en) {
        m = (st + en) / 2;
        long long int i = m, j = n - m;
        if (k - a * i - b * j > 0) {
          ans = m;
          st = m + 1;
        } else {
          en = m - 1;
        }
      }
      cout << ans << endl;
    }
  }
  return (0);
}
