#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int p, f, cs, ca, s, a;
    cin >> p >> f >> cs >> ca >> s >> a;
    if (a < s) {
      swap(a, s);
      swap(ca, cs);
    }
    long ans = 0;
    for (int i = 0; i <= cs; i++) {
      if (i * (long long int)s > p) continue;
      int o = min(cs - i, f / s);
      int myLeft = p - i * s;
      int hisLeft = f - o * s;
      int myA = min(myLeft / a, ca);
      int hisA = min(hisLeft / a, ca - myA);
      ans = max(ans, (long)i + o + myA + hisA);
    }
    cout << ans << endl;
  }
}
