#include <bits/stdc++.h>
int min(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
int main(int argc, char *argv[]) {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    int i, cs, cw, s, w, max = -10, p, f;
    scanf("%d%d%d%d%d%d", &p, &f, &cs, &cw, &s, &w);
    int mi = cs, ma = cw, ss = s, ww = w;
    if (w < s) {
      mi = cw, ma = cs, ss = w, ww = s;
    }
    for (i = 0; i <= mi; i++) {
      int cntf = 0, cntp = 0, d;
      cntp += min(i, p / ss);
      d = (p - cntp * ss) / ww;
      cntp += d;
      cntf += min(mi - min(i, p / ss), f / ss);
      cntf += min(ma - d, (f - cntf * ss) / ww);
      if ((cntf + cntp) > max) max = cntf + cntp;
    }
    printf("%d\n", max);
  }
}
