#include <bits/stdc++.h>
using namespace std;
void solve() {
  int a, b;
  cin >> a >> b;
  int c1, c2;
  cin >> c1 >> c2;
  int x, y;
  cin >> x >> y;
  if (a < b) {
    swap(a, b);
  }
  if (x > y) {
    swap(x, y);
    swap(c1, c2);
  }
  int cc1 = 0;
  int cc2 = 0;
  int w1 = 0;
  int w2 = 0;
  int i = 0;
  while (w1 + x <= a && i < c1) {
    w1 += x;
    cc1++;
    i++;
  }
  while (w2 + x <= b && i < c1) {
    w2 += x;
    cc1++;
    i++;
  }
  int mx = 0;
  int ans = 0;
  int occ1 = cc1;
  while (cc1 >= 0) {
    ans = min(c2, (a - w1) / y + (b - w2) / y);
    mx = max(mx, occ1 + ans);
    cc1--;
    w1 -= x;
    w2 += x;
    if (w2 < 0) {
      break;
    }
    if (w2 > b) {
      w2 -= x;
      occ1--;
    }
  }
  cout << mx << '\n';
}
void querySolve() {
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    solve();
  }
}
int main() { querySolve(); }
