#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long p, f, ns, na, ws, wa, ans = 0;
    cin >> p >> f >> ns >> na >> ws >> wa;
    if (wa < ws) {
      swap(ns, na);
      swap(ws, wa);
    }
    for (long long i = 0; i <= ns; ++i) {
      long long cur = 0, p_cpy = p, f_cpy = f, na_cpy = na;
      if (i * ws > p) break;
      cur += i;
      p_cpy -= i * ws;
      cur += (p_cpy / wa);
      na_cpy -= (p_cpy / wa);
      cur += min(f / ws, ns - i);
      f_cpy -= min(f / ws, ns - i) * ws;
      cur += min(f_cpy / wa, na_cpy);
      ans = max(ans, cur);
    }
    cout << ans << "\n";
  }
  return 0;
}
