#include <bits/stdc++.h>
using namespace std;
template <typename T>
void printvec(vector<T> &v, int n, int start = 0) {
  for (int i = start; i < n; i++) {
    cout << v[i] << " ";
  }
  cout << "done printing";
  cout << "\n";
}
const int mod = 1e9 + 7;
inline void swap(int &a, int &b) {
  int t = a;
  a = b;
  b = t;
}
void solve() {
  int p, f, cnts, cnta, s, a;
  cin >> p >> f >> cnts >> cnta >> s >> a;
  if (s > a) {
    swap(s, a);
    swap(cnts, cnta);
  }
  int best = 0;
  for (int p_swords = 0; p_swords <= cnts; p_swords++) {
    if (p_swords * s > p) break;
    int p_axe = min(cnta, (p - p_swords * s) / a);
    int f_swords = min(f / s, (cnts - p_swords));
    int f_axe = min((f - f_swords * s) / a, (cnta - p_axe));
    best = max(best, p_swords + p_axe + f_swords + f_axe);
  }
  cout << best << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
