#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int inf = 2000000000;
const int mod = 1007050321;
const bool aut = 788480;
const int N = 3005;
const int base = 521;
const int bag[4] = {0, 1, 6, 8};
int n, a[N], cnt[N][N];
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int ans = 0;
    int p, f, n, m, s, w;
    cin >> p >> f >> n >> m >> s >> w;
    if (p < f) swap(p, f);
    if (s > w) swap(s, w), swap(n, m);
    for (int i = 0; i <= n; ++i) {
      if (p < 1LL * i * s) break;
      int n1 = n - i;
      int j = min((p - i * s) / w, m);
      int m11 = m - j;
      int dd = min(f / s, n1);
      int cc = min((f - s * dd) / w, m11);
      ans = max(ans, i + j + dd + cc);
    }
    cout << ans << "\n";
  }
  return 0;
}
