#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char ch = getchar();
  bool flag = false;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') flag = true;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) {
    x *= 10;
    x += ch - '0';
  }
  if (flag) x = -x;
  return x;
}
int p, f, cnts, cntw, s, w;
int carry(int as) {
  int aw = min((p - as * s) / w, cntw), bs, bw;
  if (s < w) {
    bs = min(cnts - as, f / s);
    bw = min(cntw - aw, (f - s * bs) / w);
  } else {
    bw = min(cntw - aw, f / w);
    bs = min(cnts - as, (f - w * bw) / s);
  }
  return as + aw + bs + bw;
}
void solve() {
  p = read(), f = read(), cnts = read(), cntw = read(), s = read(), w = read();
  int ans = 0;
  for (int i = 0; i <= cnts && i * s <= p; i++) {
    ans = max(ans, carry(i));
  }
  cout << ans << endl;
}
int main() {
  int T;
  T = read();
  while (T--) {
    solve();
  }
  return 0;
}
