#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
template <class T1, class T2, class T3>
void printTuple(tuple<T1, T2, T3> t) {
  cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n';
}
template <class T1, class T2>
void printPair(pair<T1, T2> p) {
  cout << p.first << " " << p.second << '\n';
}
template <class T>
void printArray(vector<T> arr) {
  for (int i = 0; i < int((arr).size()); i++) {
    cout << arr[i] << " ";
  }
  cout << '\n';
}
void adjustValue(int &s, int &w, int &cnts, int &cntw) {
  if (s > w) {
    swap(s, w);
    swap(cnts, cntw);
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int p, f;
    cin >> p >> f;
    int cnts, cntw;
    cin >> cnts >> cntw;
    int s, w;
    cin >> s >> w;
    adjustValue(s, w, cnts, cntw);
    int ret = 0;
    for (int i = 0; i <= min(p / s, cnts); i++) {
      int remain_sword = cnts - i;
      int follower_sword = min(f / s, remain_sword);
      int player_remain = p - s * i, follower_remain = f - s * follower_sword;
      int player_axe = min(player_remain / w, cntw),
          remain_axe = cntw - player_axe;
      int follower_axe = min(follower_remain / w, remain_axe);
      ret = max(ret, i + follower_sword + player_axe + follower_axe);
    }
    cout << ret << '\n';
  }
}
