#include <bits/stdc++.h>
using namespace std;
void solve() {
  int p, f;
  int cnts, cntw;
  int s, w;
  cin >> p >> f;
  cin >> cnts >> cntw;
  cin >> s >> w;
  int ans = 0;
  if (s <= w) {
    for (int i = 0; i <= cnts; i++) {
      int cur = i * s;
      if (cur > p) break;
      int sec = (p - cur) / w;
      sec = min(sec, cntw);
      int cur_ans = i + sec;
      int d = f / s;
      d = min(d, cnts - i);
      cur_ans += d;
      cur_ans += min((cntw - sec), (f - d * s) / w);
      ans = max(ans, cur_ans);
    }
  } else {
    for (int i = 0; i <= cntw; i++) {
      int cur = i * w;
      if (cur > p) break;
      int sec = (p - cur) / s;
      sec = min(sec, cnts);
      int cur_ans = i + sec;
      int d = f / w;
      d = min(d, cntw - i);
      cur_ans += d;
      cur_ans += min((cnts - sec), (f - d * w) / s);
      ans = max(ans, cur_ans);
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q = 1;
  cin >> q;
  for (; q > 0; q--) {
    solve();
    cout << endl;
  }
}
