#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int tt;
  cin >> tt;
  while (tt--) {
    long long int p, f, cnts, cntw, s, w;
    cin >> p >> f;
    cin >> cnts >> cntw;
    cin >> s >> w;
    if (s >= w) {
      swap(s, w);
      swap(cnts, cntw);
    }
    long long int ans = 0;
    for (int i = 0; i <= min(cnts, p / s); i++) {
      long long int Ihaves = i;
      long long int Ihavew = min((p - s * i) / w, cntw);
      long long int Hehaves = min(cnts - i, f / s);
      long long int Hehavew = min(cntw - Ihavew, (f - s * Hehaves) / w);
      ans = max(ans, Ihaves + Ihavew + Hehaves + Hehavew);
    }
    cout << ans << endl;
  }
}
