#include <bits/stdc++.h>
using namespace std;
int main() {
  long t;
  cin >> t;
  while (t--) {
    long long p, f, cnts, cntw, s, w;
    cin >> p >> f >> cnts >> cntw >> s >> w;
    if (w < s) {
      swap(s, w);
      swap(cnts, cntw);
    }
    long long ans = 0;
    for (long i = 0; i <= cnts; i++) {
      long long s1, s2, w1, w2;
      s1 = i;
      if (s1 * s > p) break;
      w1 = min(cntw, (p - s * s1) / w);
      s2 = min(cnts - i, f / s);
      w2 = min(cntw - w1, (f - s * s2) / w);
      ans = max(ans, s1 + s2 + w1 + w2);
    }
    cout << ans << "\n";
  }
}
