#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    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 d = 0;
    for (long long ps = 0; ps <= cnts && ps * s <= p; ps++) {
      long long fs = min(f / s, cnts - ps), _p = p - ps * s, _f = f - fs * s,
                pw = min(_p / w, cntw), _cntw = cntw - pw,
                fw = min(_f / w, _cntw);
      d = max(d, ps + pw + fs + fw);
    }
    cout << d << '\n';
  }
  return 0;
}
