#include <bits/stdc++.h>
using namespace std;
int optimize(int total, int n1, int n2, int s1, int s2) {
  int count = min(n1, total / s1);
  int count1 = min(n2, (total - count * s1) / s2);
  return count1 + count;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    long long p, f;
    long long cntw, cnts;
    long long s, w;
    cin >> p >> f;
    cin >> cnts >> cntw;
    cin >> s >> w;
    long long ans = 0;
    if (s < w) {
      for (int j = 0; j <= cnts && j * s <= p; j++) {
        long long count = min((p - j * s) / w, cntw);
        long long count1 = optimize(f, cnts - j, cntw - count, s, w);
        ans = max(ans, count + j + count1);
      }
    } else {
      for (int j = 0; j <= cntw && j * w <= p; j++) {
        long long count = min((p - j * w) / s, cnts);
        long long count1 = optimize(f, cntw - j, cnts - count, w, s);
        ans = max(ans, count + j + count1);
      }
    }
    cout << ans << endl;
  }
}
