#include <bits/stdc++.h>
using namespace std;
const int MAXN = 60;
const int inf = 0x3f3f3f3f;
int n, t;
int main() {
  scanf("%d", &t);
  while (t--) {
    long long p, f, cnts, cntw, s, w;
    scanf("%lld%lld%lld%lld%lld%lld", &p, &f, &cnts, &cntw, &s, &w);
    long long ans = 0;
    if (s < w) swap(w, s), swap(cnts, cntw);
    for (int i = 0; i <= min(p / s, cnts); ++i) {
      long long a = i;
      long long b = min((p - s * i) / w, cntw);
      long long c = min(f / w, cntw - b);
      long long d = min((f - c * w) / s, cnts - a);
      ans = max(ans, a + b + c + d);
    }
    printf("%lld\n", ans);
  }
}
