#include <bits/stdc++.h>
using namespace std;
const int MAXN = 60;
const int inf = 0x3f3f3f3f;
int n, t;
int main() {
  scanf("%d", &t);
  while (t--) {
    long long p, f, cnts, cntw, s, w;
    scanf("%lld%lld%lld%lld%lld%lld", &p, &f, &cnts, &cntw, &s, &w);
    long long ans = 0;
    for (long long i = 0; i <= cnts; i++) {
      if (i * s > p) break;
      long long j = min((p - i * s) / w, cntw);
      long long x, y;
      if (s > w) {
        x = min(f / w, cntw - j);
        y = min((f - x * w) / s, cnts - i);
      } else {
        y = min(f / s, cnts - i);
        x = min((f - y * s) / w, cntw - j);
      }
      ans = max(ans, y + x + i + j);
    }
    printf("%lld\n", ans);
  }
}
