#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1e5 + 5;
const long long inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
int main() {
  int T;
  cin >> T;
  while (T--) {
    int p, f;
    cin >> p >> f;
    int cns, cnw;
    cin >> cns >> cnw;
    int s, w;
    cin >> s >> w;
    if (s > w) swap(s, w), swap(cns, cnw);
    int ans = 0;
    for (int i = 0; i <= cns; ++i) {
      int ps = min(i, p / s);
      int fs = min(cns - i, f / s);
      int pw = min(cnw, (p - ps * s) / w);
      int fw = min(cnw - pw, (f - fs * s) / w);
      ans = max(ans, ps + fs + pw + fw);
    }
    cout << ans << endl;
  }
  return 0;
}
