#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair<ll, ll>;
using vec = vector<ll>;
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll q;
  cin >> q;
  while (q--) {
    ll a, n, x, y;
    cin >> a >> n >> x >> y;
    ll x1, y1;
    y1 = ceil((a - y * n) * 1.0 / (x - y));
    y1--;
    x1 = (n * x - a) / (x - y) + 1;
    if (y1 < 0 || x1 > n) {
      cout << -1 << "\n";
    } else
      cout << min(y1, n) << "\n";
  }
  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
  return 0;
}
