#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long p, f, cnts, cntw, s, w;
    cin >> p >> f >> cnts >> cntw >> s >> w;
    if (s > w) swap(s, w), swap(cnts, cntw);
    int ans = 0;
    for (int i = 0; i <= cnts; i++) {
      if (i * s > p) break;
      int s1 = i;
      int a1 = min((p - (s1 * s)) / w, cntw);
      int s2 = min(f / s, cnts - s1);
      int a2 = min((f - (s2 * s)) / w, cntw - a1);
      ans = max(ans, s1 + a1 + s2 + a2);
    }
    cout << ans << "\n";
  }
  return 0;
}
