#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (T i : v) os << i << ' ';
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (T i : v) os << i << ' ';
  return os;
}
template <class T, class S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  os << v.first << ' ' << v.second;
  return os;
}
template <class T, class S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' ';
  return os;
}
template <class T, class S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v) {
  for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' ';
  return os;
}
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
    "avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const long long mod = 1e9 + 7;
long long takemod(long long a) { return ((a % mod) + mod) % mod; }
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long fast_exp(long long base, long long expo) {
  long long res = 1;
  while (expo > 0) {
    if (expo & 1) res = (res * base) % mod;
    base = (base * base) % mod;
    expo >>= 1;
  }
  return res;
}
long long modinv(long long a) { return takemod(fast_exp(takemod(a), mod - 2)); }
void solve() {
  long long cap1, cap2;
  cin >> cap1 >> cap2;
  long long count1, count2;
  cin >> count1 >> count2;
  long long weight1, weight2;
  cin >> weight1 >> weight2;
  long long ans = 0;
  for (long long i = (0); i < (count1 + 1); i++) {
    long long val = weight1 * i;
    if (val > cap1)
      break;
    else {
      long long remcap1 = cap1 - val;
      if (count2 * weight2 <= remcap1) {
        long long tempans = i + count2;
        long long remcount1 = count1 - i;
        ans = max(ans, tempans + min(cap2 / weight1, remcount1));
      } else {
        long long tempans = i + (remcap1 / weight2);
        long long remcount1 = count1 - i;
        long long remcount2 = count2 - (remcap1 / weight2);
        if (weight1 <= weight2) {
          if (weight1 * remcount1 >= cap2) {
            ans = max(ans, tempans + min(cap2 / weight1, remcount1));
          } else {
            tempans += remcount1;
            long long remcap2 = (cap2 - remcount1 * weight1);
            tempans += min(remcap2 / weight2, remcount2);
            ans = max(ans, tempans);
          }
        } else {
          if (weight2 * remcount2 >= cap2) {
            ans = max(ans, tempans + min(cap2 / weight2, remcount2));
          } else {
            tempans += remcount2;
            long long remcap2 = (cap2 - remcount2 * weight2);
            tempans += min(remcap2 / weight1, remcount1);
            ans = max(ans, tempans);
          }
        }
      }
    }
  }
  for (long long i = (0); i < (count1 + 1); i++) {
    long long val = weight1 * i;
    if (val > cap2)
      break;
    else {
      long long remcap2 = cap2 - val;
      if (count2 * weight2 <= remcap2) {
        long long tempans = i + count2;
        long long remcount1 = count1 - i;
        ans = max(ans, tempans + min(cap1 / weight1, remcount1));
      } else {
        long long tempans = i + (remcap2 / weight2);
        long long remcount1 = count1 - i;
        long long remcount2 = count2 - (remcap2 / weight2);
        if (weight1 <= weight2) {
          if (weight1 * remcount1 >= cap1) {
            ans = max(ans, tempans + min(cap1 / weight1, remcount1));
          } else {
            tempans += remcount1;
            long long remcap1 = (cap1 - remcount1 * weight1);
            tempans += min(remcap1 / weight2, remcount2);
            ans = max(ans, tempans);
          }
        } else {
          if (weight2 * remcount2 >= cap1) {
            ans = max(ans, tempans + min(cap1 / weight2, remcount2));
          } else {
            tempans += remcount2;
            long long remcap1 = (cap1 - remcount2 * weight2);
            tempans += min(remcap1 / weight1, remcount1);
            ans = max(ans, tempans);
          }
        }
      }
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
