#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long n, k, t, m, q, flag = 0;
long long power(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long gcd(long long a, long long b) {
  if (b > a) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    long long c1, c2;
    cin >> c1 >> c2;
    long long s, a;
    cin >> s >> a;
    long long ans = 0;
    for (int i = 0; i < c1 + 1; i++) {
      long long n1 = n, m1 = m;
      long long val = 0;
      if (n1 < i * s)
        continue;
      else
        val += i + min(c2, (n1 - i * s) / a);
      if (s > a) {
        val += min(m1 / a, c2 - min(c2, (n1 - i * s) / a));
        m1 -= min(m1 / a, c2 - min(c2, (n1 - i * s) / a)) * a;
        val += min(m1 / s, c1 - i);
      } else {
        val += min(m1 / s, c1 - i);
        m1 -= min(m1 / s, c1 - i) * s;
        val += min(m1 / a, c2 - min(c2, (n1 - i * s) / a));
      }
      ans = max(val, ans);
    }
    cout << ans << "\n";
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
