#include <bits/stdc++.h>
using namespace std;
void solve() {
  int p, f, cnts, cnta, ws, wa;
  cin >> p >> f >> cnts >> cnta >> ws >> wa;
  if (wa < ws) {
    swap(ws, wa);
    swap(cnts, cnta);
  }
  int ans = 0, a, b, c;
  for (int i = 0; i <= min(cnts, p / ws); ++i) {
    a = min((p - i * ws) / wa, cnta);
    int d = cnts - i;
    int e = cnta - a;
    b = min(d, f / ws);
    c = min(e, (f - ws * b) / wa);
    ans = max(ans, i + a + b + c);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
