#include <bits/stdc++.h>
using namespace std;
int maxrob(int p, int f, int cnt_s, int cnt_w, int s, int w) {
  if (p > f) {
    swap(p, f);
  }
  if (s > w) {
    swap(cnt_s, cnt_w);
    swap(s, w);
  }
  long long s_total = (long long)cnt_s * s;
  if ((p + f) <= s_total) {
    return (p / s) + (f / s);
  }
  int w_cnt_max = min(((p + f) - s_total) / w, (long long)cnt_w);
  int answer = 0;
  for (int k = 0; k <= w_cnt_max; ++k) {
    if ((long long)w * k > p) break;
    int res = 0;
    int s_cnt_p = min((p - w * k) / s, cnt_s);
    int s_cnt_f = cnt_s - s_cnt_p;
    res += s_cnt_p;
    if ((long long)s * s_cnt_f > f) {
      s_cnt_f = (f / s);
    }
    res += s_cnt_f;
    res += min((p - s * s_cnt_p) / w + (f - s * s_cnt_f) / w, cnt_w);
    if (answer < res) answer = res;
  }
  return answer;
}
int main() {
  int T;
  cin >> T;
  while (T-- != 0) {
    int p, f;
    cin >> p >> f;
    int cnt_s, cnt_w;
    cin >> cnt_s >> cnt_w;
    int s, w;
    cin >> s >> w;
    cout << maxrob(p, f, cnt_s, cnt_w, s, w) << endl;
  }
}
