#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long p, f;       cin >> p >> f;       long long cnt1, cnt2;       cin >> cnt1 >> cnt2;       long long s, w;       cin >> s >> w;       if (s > w) {         swap(s, w);         swap(cnt1, cnt2);       }       long long ans = 0;       for (long long i = 0; i <= min(cnt1, p / s); i++) {         long long cnt = i;         long long tmpp = p - i * s;         cnt += (min(cnt2, tmpp / w));         long long tmpw = cnt2 - min(cnt2, tmpp / w), tmps = cnt1 - i;         cnt += min(tmps, f / s);         long long tmpf = f - min(tmps, f / s) * s;         cnt += min(tmpw, tmpf / w);         ans = max(ans, cnt);       }       cout << ans << endl;     }     return 0;   }   