#include <bits/stdc++.h>
using namespace std;
int p, first, cnts, cntw, S, W;
int solve(long long picked) {
  int np = p, nf = first, cnt1 = cnts, cnt2 = cntw;
  long long temp = picked;
  np -= (picked * S);
  cnt1 -= picked;
  if (np >= W) {
    temp += min(np / W, cnt2);
    cnt2 -= min(np / W, cnt2);
  }
  if (S <= W) {
    temp += min(nf / S, cnt1);
    nf -= (min(nf / S, cnt1) * S);
    temp += min(nf / W, cnt2);
  } else {
    temp += min(nf / W, cnt2);
    nf -= (min(nf / W, cnt2) * W);
    temp += min(nf / S, cnt1);
  }
  return temp;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &p, &first);
    scanf("%d %d", &cnts, &cntw);
    scanf("%d %d", &S, &W);
    long long ans = 0, temp;
    for (int pickedS = 0; pickedS <= min(cnts, p / S); pickedS++) {
      temp = solve(pickedS);
      ans = max(ans, temp);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
