#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int acap, bcap;
    cin >> acap >> bcap;
    int cnt1, cnt2;
    cin >> cnt1 >> cnt2;
    int s1, s2;
    cin >> s1 >> s2;
    if (s2 < s1) {
      swap(s1, s2);
      swap(cnt1, cnt2);
    }
    int ans = 0;
    int lim = min(cnt1, acap / s1);
    for (int i = 0; i <= lim; ++i) {
      int x = min(cnt2, (acap - i * s1) / s2);
      int left1 = cnt1 - i;
      int left2 = cnt2 - x;
      int y = min(left1, bcap / s1);
      int z = min(left2, (bcap - y * s1) / s2);
      ans = max(ans, x + y + z + i);
    }
    cout << ans << "\n";
  }
}
