#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t, n, i, j;
  cin >> t;
  while (t--) {
    long long p, f, cs, cw, s, w;
    cin >> p >> f;
    cin >> cs >> cw;
    cin >> s >> w;
    long long r1 = cs, r2 = s;
    long long ans1 = 0, ps = 0, pw = 0, fs = 0, fw = 0, ans2 = 0, ans3 = 0,
              ans4 = 0;
    if (s > w) {
      cs = cw;
      cw = r1;
      s = w;
      w = r2;
    }
    {
      for (i = 0; i <= cs; i++) {
        if (i * s > p) continue;
        ps = i;
        fs = min(f / s, cs - i);
        pw = min((p - i * s) / w, cw);
        fw = min((f - fs * s) / w, cw - pw);
        ans1 = max(ans1, ps + fs + pw + fw);
      }
      cout << ans1 << endl;
    }
  }
}
