#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t, p, f, cnts, cntw, s, w, ans, n, i, ii, sf, wf, sff, wff;
  cin >> t;
  while (t--) {
    cin >> p >> f;
    cin >> cnts >> cntw;
    cin >> s >> w;
    n = min(p / s, cnts);
    ans = 0;
    for (i = 0; i <= n; i++) {
      ii = min(cntw, (p - i * s) / w);
      sf = min(cnts - i, f / s);
      wf = min(cntw - ii, (f - sf * s) / w);
      wff = min(cntw - ii, f / w);
      sff = min(cnts - i, (f - wff * w) / s);
      ans = max(ans, (i + ii + max(sf + wf, sff + wff)));
    }
    cout << ans << endl;
  }
}
