#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long p, f, cnts, cntw, s, w, ans = 0;
    cin >> p >> f >> cnts >> cntw >> s >> w;
    if (s > w) {
      swap(s, w);
      swap(cnts, cntw);
    }
    if (p / s + f / s <= cnts) {
      cout << p / s + f / s << endl;
    } else {
      int nowME = min(p / s, cnts), nowF = cnts - min(p / s, cnts);
      ans = cnts;
      for (int i = nowF; i <= min(f / s, cnts); ++i) {
        ans = max(ans,
                  nowME - (i - nowF) + i +
                      min((p - (nowME - (i - nowF)) * s) / w + (f - i * s) / w,
                          cntw));
      }
      cout << ans << endl;
    }
  }
}
