#include <bits/stdc++.h>
using namespace std;
struct item {
  long long count, weight;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  item a, b;
  long long t, me, frend, cW, cS, w, s;
  cin >> t;
  while (t--) {
    long long ans = 0;
    cin >> me >> frend;
    if (me < frend) {
      swap(me, frend);
    }
    cin >> a.count >> b.count;
    cin >> a.weight >> b.weight;
    if (a.weight > b.weight) {
      swap(a, b);
    }
    for (long long cnta = 0;
         cnta <= min(a.count, (long long)(floor(1.0 * me / a.weight)));
         cnta++) {
      item atmp = a, btmp = b;
      long long tmpMe = me, tmpFrend = frend, curAns = 0;
      long long aForMe = min(cnta, me / a.weight);
      long long aForFrend = a.count - cnta;
      curAns += cnta;
      tmpMe -= cnta * a.weight;
      curAns += min(aForFrend, tmpFrend / a.weight);
      tmpFrend -= min(aForFrend, tmpFrend / a.weight) * a.weight;
      curAns += min(tmpMe / b.weight + tmpFrend / b.weight, b.count);
      ans = max(ans, curAns);
    }
    cout << ans << endl;
  }
}
