#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long p, q;
    cin >> p >> q;
    long long n, m;
    cin >> n >> m;
    long long wn, wm;
    cin >> wn >> wm;
    if (wn > wm) {
      swap(wn, wm);
      swap(n, m);
    }
    long long maxi = 0, i = 3;
    for (long long i = 0; i <= n; i++) {
      long long z = p, val = 0, s = m;
      long long z3 = min(i, z / wn);
      z -= z3 * wn;
      val += z3;
      val += min(z / wm, s);
      s -= min(z / wm, s);
      long long z1 = q, val1 = 0;
      long long b = min(n - z3, z1 / wn);
      val1 += b;
      z1 -= b * wn;
      val1 += min(z1 / wm, s);
      maxi = max(maxi, val + val1);
    }
    cout << maxi << "\n";
  }
}
