#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int p, f;
    cin >> p >> f;
    int cnts, cntw;
    cin >> cnts >> cntw;
    int s, w;
    cin >> s >> w;
    int ans = 0;
    if (s > w) {
      swap(s, w);
      swap(cnts, cntw);
    }
    for (int i = 0; i <= cnts; i++) {
      int x = min(p / s, i);
      int k = p - (x * s);
      int y = min(k / w, cntw);
      int nn = cnts - x, mm = cntw - y;
      int pp = min(f / s, nn);
      int l = f - (pp * s);
      int qq = min(l / w, mm);
      ans = max(ans, (x + y + pp + qq));
    }
    cout << ans << endl;
  }
  return 0;
}
