#include <bits/stdc++.h>
using namespace std;
int main() {
  int TC;
  cin >> TC;
  while (TC--) {
    int p, f, cnts, cntw, s, w;
    cin >> p >> f >> cnts >> cntw >> s >> w;
    if (s < w) {
      swap(s, w);
      swap(cnts, cntw);
    }
    int maxi = 0;
    for (int i = 0; i <= min(p / w, cntw); i++) {
      int pw = i;
      int ps = min((p - i * w) / s, cnts);
      int fw, fs;
      int cntW = cntw - i;
      int cntS = cnts - ps;
      fw = min(cntW, f / w);
      if (f / w > cntW) {
        fs = min(cntS, (f - cntW * w) / s);
      } else {
        fs = 0;
      }
      int total = ps + pw + fs + fw;
      maxi = max(maxi, total);
    }
    cout << maxi << '\n';
  }
  return 0;
}
