#include <bits/stdc++.h>
using namespace std;
int n;
int p, f;
int cs, cw, s, w;
void solve() {
  if (s > w) {
    swap(s, w);
    swap(cs, cw);
  }
  if (p / s + f / s <= cs) {
    cout << p / s + f / s << "\n";
    return;
  }
  int ans = 0;
  for (int i = 0; i <= cs; ++i) {
    if (p < i * s) break;
    int ps = i;
    int fs = min(cs - ps, f / s);
    int pw = min(cw, (p - s * ps) / w);
    int fw = min(cw - pw, (f - s * fs) / w);
    int local_ans = ps + fs + pw + fw;
    ans = max(ans, local_ans);
  }
  cout << ans << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> p >> f;
    cin >> cs >> cw;
    cin >> s >> w;
    solve();
  }
  return 0;
}
