#include <bits/stdc++.h>
using namespace std;
const long long Maxn = 200 * 1000 + 1;
const long double pi = acos(-1);
const long long mod = 1000000007;
template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
  for (auto x : A) out << x << " ";
  return out;
}
template <class T>
ostream &operator<<(ostream &out, unordered_set<T> &A) {
  for (auto x : A) out << x << " ";
  return out;
}
template <class T1, class T2>
T1 powr(T1 a, T2 b) {
  T1 res = 1;
  for (long long i = 1; i < b + 1; i++) res = res * a;
  return res;
}
long long calc(long long a, long long b, long long c) {
  return abs(a - b) + abs(a - c) + abs(b - c);
}
long long cnt(long long t) {
  long long c = 0;
  while (t > 0) {
    t = t & (t - 1);
    c++;
  }
  return c;
}
long long binpow(long long a, long long b) {
  a = a % mod;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return (res + mod) % mod;
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long p, f, cnts, cntw, s, w;
    cin >> p >> f >> cnts >> cntw >> s >> w;
    if (s > w) {
      swap(s, w);
      swap(cnts, cntw);
    }
    long long ans = 0;
    for (long long i = 0; i <= cnts; i++) {
      if (i * s > p) break;
      long long g = 0;
      g += (min(cnts - i, f / s));
      long long cnt = cntw;
      long long fi = f - g * s;
      long long pi = p - i * s;
      long long d = min(cnt, fi / w);
      g += d;
      cnt -= d;
      g += min(cnt, pi / w);
      ans = max(ans, g + i);
    }
    cout << ans << endl;
  }
}
