#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long T;
  cin >> T;
  for (long long testcase = 0; testcase < T; ++testcase) {
    long long p, f;
    cin >> p >> f;
    long long cnts, cntw;
    cin >> cnts >> cntw;
    long long s, w;
    cin >> s >> w;
    if (s > w) {
      swap(s, w);
      swap(cnts, cntw);
    }
    long long rans = 0;
    for (long long i = 0; i <= min(p / s, cnts); ++i) {
      long long ans = 0;
      long long s_used_by_p = i;
      ans += s_used_by_p;
      long long temp_p = p - s_used_by_p * s;
      ans += min(temp_p / w, cntw);
      long long temp_cntw = cntw - min(temp_p / w, cntw);
      long long s_used_by_f = cnts - s_used_by_p;
      ans += min(s_used_by_f, f / s);
      long long temp_f = f - min(s_used_by_f, f / s) * s;
      ans += min(temp_f / w, temp_cntw);
      rans = max(rans, ans);
    }
    cout << rans << "\n";
  }
}
