#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long p, f;
    long long cnts, cntw, s, w;
    scanf("%lld%lld%lld%lld%lld%lld", &p, &f, &cnts, &cntw, &s, &w);
    int ans = 0;
    if (s > w) {
      swap(s, w);
      swap(cnts, cntw);
    }
    for (int i = 0; i <= cnts; i++) {
      if (p < i * s) break;
      int tmp = i + min(cntw, (p - i * s) / w);
      long long cs = cnts - i;
      long long cw = cntw - min(cntw, (p - i * s) / w);
      int x = min(cs, f / s);
      tmp += x + min(cw, (f - x * s) / w);
      ans = max(tmp, ans);
    }
    printf("%d\n", ans);
  }
}
