#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
using namespace std;
void xuly() {
  int t;
  cin >> t;
  while (t--) {
    long long p, f, n, m, s, w, ans = 0;
    cin >> p >> f;
    cin >> n >> m >> s >> w;
    if (s > w) swap(s, w), swap(n, m);
    for (int i = 0; i <= n; i++) {
      if (i * s > p) break;
      long long last = p - i * s;
      last /= w;
      long long take = min(last, m);
      m -= take;
      int t1 = take;
      take += i;
      n -= i;
      long long takef = min(f / s, n);
      last = f - takef * s;
      takef += min(last / w, m);
      m += t1;
      n += i;
      ans = max(ans, take + takef);
    }
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  xuly();
}
