#include <bits/stdc++.h>
using namespace std;
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, set<T> S) {
  os << "{ ";
  for (auto s : S) os << s << " ";
  return os << "}";
}
template <class L, class R>
ostream& operator<<(ostream& os, map<L, R> M) {
  os << "{ ";
  for (auto m : M) os << "(" << m.F << ":" << m.S << ") ";
  return os << "}";
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " |";
  __f(comma + 1, args...);
}
void solve() {
  int p, f;
  cin >> p >> f;
  int lc, hc;
  cin >> lc >> hc;
  int lw, hw;
  cin >> lw >> hw;
  if (lw > hw) {
    swap(lc, hc);
    swap(lw, hw);
  }
  int mxw = 0;
  for (int i = 0; i <= lc; ++i) {
    int plc = min(i, p / lw);
    int phc = min(hc, (p - plc * lw) / hw);
    int tlc = min(lc - plc, f / lw);
    int thc = min(hc - phc, (f - tlc * lw) / hw);
    mxw = max(mxw, plc + tlc + phc + thc);
  }
  cout << mxw << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1, tc = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
