#include <bits/stdc++.h>
using namespace std;
struct msp {
  long long cnt, w;
} we[10];
signed main() {
  std::ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    long long p, f;
    cin >> p >> f;
    cin >> we[1].cnt >> we[2].cnt >> we[1].w >> we[2].w;
    if (we[1].w > we[2].w) swap(we[1], we[2]);
    long long ans = 0;
    for (int i = 0; i <= we[1].cnt && i * we[1].w <= p; ++i) {
      long long nowans = i;
      long long pres = p - i * we[1].w;
      long long s2 = min(pres / we[2].w, we[2].cnt);
      nowans += s2;
      long long we2lft = we[2].cnt - s2;
      long long f1cnt = min(f / we[1].w, we[1].cnt - i);
      nowans += f1cnt;
      long long fres = f - f1cnt * we[1].w;
      nowans += min(fres / we[2].w, we2lft);
      ans = max(ans, nowans);
    }
    cout << ans << '\n';
  }
  return 0;
}
