#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
bool comp(int a, int b) { return a >= b; }
int ff(int p, int f, int cnts, int cntw, int s, int w) {
  int ksp = p / s;
  ksp = min(ksp, cnts);
  p -= ksp * s;
  cnts -= ksp;
  int ksf = f / s;
  ksf = min(ksf, cnts);
  f -= ksf * s;
  return ksp + ksf + min(int(p / w) + int(f / w), cntw);
}
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    int p, f, cnts, cntw, s, w;
    cin >> p >> f >> cnts >> cntw >> s >> w;
    int sres = 0, res = 0;
    if (s > w) {
      swap(cnts, cntw);
      swap(s, w);
    }
    if (p < f) {
      swap(p, f);
    }
    for (int i = 0; i <= min(cnts, int(p / s)); ++i) {
      int kwp = min(int((p - i * s) / w), cntw);
      int ksf = min(int(f / s), cnts - i);
      sres = kwp + ksf + i;
      int kwf = min(cntw - kwp, int((f - ksf * s) / w));
      sres += kwf;
      if (sres > res) {
        res = sres;
      }
    }
    cout << res << endl;
  }
}
