#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
int64_t can_take(int64_t S, int64_t W, int64_t CS, int64_t CW, int64_t P) {
  if (S > W) return can_take(W, S, CW, CS, P);
  if (S * CS >= P) return P / S;
  return CS + min((P - S * CS) / W, CW);
}
void run_case() {
  int64_t P, F, CS, CW, S, W;
  cin >> P >> F >> CS >> CW >> S >> W;
  int64_t best = 0;
  for (int64_t cs = 0; cs <= CS; cs++)
    if (cs * S <= P) {
      int64_t cw = min((P - cs * S) / W, CW);
      best = max(best, cs + cw + can_take(S, W, CS - cs, CW - cw, F));
    }
  cout << best << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tests;
  cin >> tests;
  while (tests-- > 0) run_case();
}
