#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long p, f;
    cin >> p >> f;
    long long cnt_s, cnt_w, s, w;
    cin >> cnt_s >> cnt_w >> s >> w;
    long long ans = 0;
    if (s > w) {
      swap(s, w);
      swap(cnt_s, cnt_w);
    }
    for (long long i = 0; i <= min(p / s, cnt_s); i++) {
      long long curr_p = p - i * s, curr_w = cnt_w, curr_s = cnt_s - i,
                curr_f = f;
      long long curr_ans = i;
      curr_ans += min(cnt_w, curr_p / w);
      curr_w -= min(cnt_w, curr_p / w);
      curr_ans += min(curr_s, curr_f / s);
      curr_f -= min(curr_s, curr_f / s) * s;
      curr_ans += min(curr_w, curr_f / w);
      ans = max(ans, curr_ans);
    }
    cout << ans << "\n";
  }
  return 0;
}
