#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long p, f, cnts, cntw, s, w;
  cin >> p >> f >> cnts >> cntw >> s >> w;
  long long res = 0;
  for (long long ss1 = 0; ss1 <= cnts && s * ss1 <= p; ss1++) {
    long long ww1 = min((p - s * ss1) / w, cntw);
    long long ss = cnts - ss1;
    long long ww = cntw - ww1;
    long long ss2, ww2;
    if (s < w) {
      ss2 = min(ss, f / s);
      ww2 = min(ww, (f - s * ss2) / w);
    } else {
      ww2 = min(ww, f / w);
      ss2 = min(ss, (f - w * ww2) / s);
    }
    res = max(res, ss1 + ss2 + ww1 + ww2);
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(nullptr);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
