#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 ans = 0;
    for (int t1 = 0; t1 <= cnts; t1++) {
      if (1ll * t1 * s > p) break;
      int t2 = min((p - t1 * s) / w, cntw);
      int rcnts = cnts - t1;
      int rcntw = cntw - t2;
      if (s <= w) {
        int t3 = min(rcnts, f / s);
        int t4 = min(rcntw, (f - t3 * s) / w);
        ans = max(ans, t1 + t2 + t3 + t4);
      } else {
        int t3 = min(rcntw, f / w);
        int t4 = min(rcnts, (f - t3 * w) / s);
        ans = max(ans, t1 + t2 + t3 + t4);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
