#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long p, q, a, b, wa, wb;
  cin >> p >> q >> a >> b >> wa >> wb;
  long long res = 0;
  if (wa < wb) {
    for (long long i = 0; i <= a; i++) {
      if (p < (i * wa)) continue;
      long long tb = b, ta = a, tp = p, tq = q;
      long long cur = 0;
      tp -= (i)*wa;
      ta -= i;
      cur += i;
      if (tp > 0) {
        cur += min(tp / wb, tb);
        tb -= min(tp / wb, tb);
      }
      cur += min(tq / wa, ta);
      tq -= wa * (min(tq / wa, ta));
      if (tq > 0) {
        cur += min(tq / wb, tb);
        tb -= min(tq / wb, tb);
      }
      res = max(res, cur);
    }
  } else {
    for (long long i = 0; i <= b; i++) {
      if (p < (i * wb)) continue;
      long long tb = b, ta = a, tp = p, tq = q;
      long long cur = 0;
      tp -= (i)*wb;
      tb -= i;
      cur += i;
      if (tp > 0) {
        cur += min(tp / wa, ta);
        ta -= min(tp / wa, ta);
      }
      cur += min(tq / wb, tb);
      tq -= wb * min(tq / wb, tb);
      if (tq > 0) {
        cur += min(tq / wa, ta);
        ta -= min(tq / wa, ta);
      }
      res = max(res, cur);
    }
  }
  cout << res << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
