#include <bits/stdc++.h>
using namespace std;
long long t, p, f, cs, cw, s, w;
int main() {
  cin >> t;
  for (int l = 0; l < t; l++) {
    cin >> p >> f >> cs >> cw >> s >> w;
    long long ans = 0;
    long long mi = min(cs, p / s);
    for (int i = 0; i <= mi; i++) {
      long long p_temp = p - i * s;
      long long item_p = i, freq_s = cs - i;
      long long add = min(cw, p_temp / w);
      item_p += add;
      p_temp -= add * w;
      long long freq_w = cw - add;
      long long murah = min(s, w), mahal = max(s, w);
      long long freq_murah = freq_s, freq_mahal = freq_w;
      if (murah == w) swap(freq_murah, freq_mahal);
      add = min(freq_murah, f / murah);
      long long f_temp = f - add * murah;
      long long item_f = add;
      add = min(freq_mahal, f_temp / mahal);
      f_temp -= add * mahal;
      item_f += add;
      long long total = item_p + item_f;
      ans = max(ans, total);
    }
    cout << ans << endl;
  }
}
