#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    long long q, f, cnts, cntw, s, w;
    cin >> q >> f >> cnts >> cntw >> s >> w;
    if (s > w) {
      swap(s, w);
      swap(cnts, cntw);
    }
    long long sum = 0;
    for (long long i = 0; i <= cnts; ++i) {
      if (i * s > q) {
        break;
      }
      long long v = min(cntw, (q - i * s) / w);
      long long v2 = min(f / s, cnts - i);
      sum = max(sum, i + v2 + v + min(cntw - v, (f - v2 * s) / w));
    }
    cout << sum << "\n";
  }
}
