#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    long long p, f;
    cin >> p >> f;
    long long cnts, cntw;
    cin >> cnts >> cntw;
    long long s, w;
    cin >> s >> w;
    long long answer = 0;
    for (long long my_s = 0; my_s <= min(p / s, cnts); ++my_s) {
      long long my_w = min(cntw, (p - my_s * s) / w);
      long long left_s = cnts - my_s;
      long long left_w = cntw - my_w;
      long long his_s = 0, his_w = 0;
      long long temp_s = s;
      long long temp_w = w;
      if (temp_s > temp_w) {
        swap(left_s, left_w);
        swap(temp_s, temp_w);
      }
      his_s = min(f / temp_s, left_s);
      his_w = min((f - his_s * temp_s) / temp_w, left_w);
      answer = max(answer, my_s + my_w + his_s + his_w);
    }
    cout << answer << '\n';
  }
}
