#include <bits/stdc++.h>
using namespace std;
long long t, p, f, cnts, cntw, s, w;
inline long long work(long long x, long long cnta, long long cntb, long long a,
                      long long b) {
  long long cnt = min(cnta, x / a);
  x -= cnt * a;
  cnta -= cnt;
  cnt += min(cntb, x / b);
  cntb -= min(cntb, x / b);
  return cnt;
}
signed main() {
  cin >> t;
  while (t--) {
    cin >> p >> f >> cnts >> cntw >> s >> w;
    long long ans = 0;
    if (s > w) swap(cnts, cntw), swap(s, w);
    for (long long i = 0; i <= min(cnts, p / s); i++) {
      long long j = (p - i * s) / w;
      long long tot = i + j + work(f, cnts - i, cntw - j, s, w);
      ans = max(ans, tot);
    }
    cout << ans << endl;
  }
  return 0;
}
