#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int p, r;
    cin >> p >> r;
    int P = p, R = r;
    int sc, ac, ap, sp;
    cin >> sc >> ac >> sp >> ap;
    if (sp > ap) {
      swap(sc, ac);
      swap(sp, ap);
    }
    int mx = 0;
    int SC, AC, SP, AP;
    SC = sc;
    AC = ac, SP = sp, AP = ap;
    for (int i = 0; i <= SC; i++) {
      r = R, p = P;
      ac = AC, sp = SP, ap = AP, sc = SC;
      if (i > sc or sp * i > p) break;
      sc -= i;
      int ans = 0;
      ans += i;
      p -= i * sp;
      int f = r / sp;
      f = min(f, sc);
      ans += f;
      sc -= f;
      r -= f * sp;
      f = p / ap;
      f = min(f, ac);
      ans += f;
      ac -= f;
      f = r / ap;
      f = min(ac, f);
      ans += f;
      mx = max(mx, ans);
    }
    cout << mx << endl;
  }
}
