#include <bits/stdc++.h>
using namespace std;
long long T, p, f, sn, sm, wn, wm, ans, ans1, sn1, sm1, ysum, ff;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int main() {
  T = read();
  while (T--) {
    p = read();
    f = read();
    sn = read();
    sm = read();
    wn = read();
    wm = read();
    if (wn > wm) {
      swap(sn, sm);
      swap(wn, wm);
    }
    ans = 0;
    for (int i = 0; i <= min(sn, p / wn); i++) {
      ysum = p - i * wn;
      ans1 = i + ysum / wm;
      sm1 = sm - ysum / wm;
      sn1 = min(sn - i, f / wn);
      ans1 += sn1;
      ff = f - sn1 * wn;
      ff /= wm;
      ans1 += min(ff, sm1);
      ans = max(ans, ans1);
    }
    cout << ans << endl;
  }
  return 0;
}
