#include <bits/stdc++.h>
using namespace std;
int p, f;
int n1, n2;
int w1, w2;
void solution() {
  cin >> p >> f;
  cin >> n1 >> n2;
  cin >> w1 >> w2;
  if (p > f) swap(p, f);
  if (w1 > w2) {
    swap(w1, w2);
    swap(n1, n2);
  }
  int best = 0;
  for (int x = 0; x <= n2; x++) {
    int a = p, b = f;
    int n2a = x, n1a, n2b, n1b;
    int cur = 0;
    a -= n2a * w2;
    cur += n2a;
    if (a < 0) break;
    n1a = min(n1, a / w1);
    cur += n1a;
    n1b = min(n1 - n1a, b / w1);
    cur += n1b;
    b -= n1b * w1;
    n2b = min(n2 - n2a, b / w2);
    cur += n2b;
    best = max(best, cur);
  }
  cout << best << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solution();
  }
  return 0;
}
