#include <bits/stdc++.h>
using namespace std;
using vl = vector<long long>;
using vpl = vector<pair<long long, long long>>;
using vs = vector<string>;
using pl = pair<long long, long long>;
using ll = long long int;
using vb = vector<bool>;
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
void printcase(ll x) { cout << "Case #" << x << ": "; }
void read(vector<ll> &v, ll &n) {
  for (ll i = 0; i < n; ++i) cin >> v[i];
}
void read(ll &x) { cin >> x; }
void read(string &s) { cin >> s; }
void read(int &x) { cin >> x; }
void read(ll a[], ll &n) {
  for (ll i = 0; i < n; ++i) cin >> a[i];
}
void print() { cout << endl; }
void write(vector<ll> &v, ll &n) {
  for (ll i = 0; i < n; ++i) cout << v[i] << " ";
  cout << endl;
}
void write(vector<ll> &v) {
  ll n = v.size();
  for (ll i = 0; i < n; ++i) cout << v[i] << " ";
  cout << endl;
}
void write(ll x) { cout << x << endl; }
void write(string &s) { cout << s << endl; }
void write(int &x) { cout << x << endl; }
void write(ll a[], ll &n) {
  for (ll i = 0; i < n; ++i) cout << a[i] << " ";
  cout << endl;
}
void solve() {
  ll b1, b2, n1, n2, w1, w2;
  cin >> b1 >> b2 >> n1 >> n2 >> w1 >> w2;
  ll res = 0;
  if (w2 < w1) {
    swap(w1, w2);
    swap(n1, n2);
  }
  ll s1, s2, wa1, wa2;
  for (ll i = 0; i <= n1; i++) {
    s1 = min(i, b1 / w1);
    s2 = min(n1 - s1, b2 / w1);
    wa1 = min(n2, (b1 - s1 * w1) / w2);
    wa2 = min(n2 - wa1, (b2 - s2 * w1) / w2);
    res = max(res, s1 + s2 + wa1 + wa2);
  }
  cout << res << endl;
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  ll t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
