#include <bits/stdc++.h>
using namespace std;
int n, T, m, s, w, vs, vw;
int main() {
  cin >> T;
  while (T--) {
    int ans = 0;
    cin >> n >> m;
    cin >> s >> w;
    cin >> vs >> vw;
    if (vs > vw) swap(vs, vw), swap(s, w);
    for (int i = 0; i <= s && i * vs <= n; i++) {
      int now = vs * i, res = i;
      int bn = n, bm = m, bw = w;
      n -= now;
      res += min(n / vw, w);
      w -= min(n / vw, w);
      res += min(m / vs, s - i);
      m -= min(m / vs, s - i) * vs;
      res += min(m / vw, w);
      ans = max(ans, res);
      n = bn, m = bm, w = bw;
    }
    cout << ans << endl;
  }
  return 0;
}
