#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int p, f, cnts, cntw, s, w;
    cin >> p >> f >> cnts >> cntw >> s >> w;
    int res = 0, ans = 0, cur, ps, pw, fs, fw;
    if (p < f) swap(p, f);
    if (s > w) {
      swap(s, w);
      swap(cnts, cntw);
    }
    for (int i = 0; i <= cnts; i++) {
      ps = min(i, p / s);
      pw = min(cntw, (p - ps * s) / w);
      fs = min(cnts - ps, f / s);
      int remf = f - fs * s;
      fw = min(cntw - pw, remf / w);
      cur = ps + pw + fs + fw;
      res = max(res, cur);
    }
    cout << res << endl;
  }
}
