#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int p, f;
    long long int cs, cw;
    long long int s, w;
    cin >> p >> f >> cs >> cw >> s >> w;
    if (s > w) {
      swap(s, w);
      swap(cs, cw);
    }
    long long int maxi = 0;
    for (int i = 0; i * s <= p && i <= cs; i++) {
      long long int count = 0;
      long long int pi = p - i * s;
      count = count + i;
      long long int cwi = cw - (pi / w);
      long long int y = 0;
      cwi = max(y, cwi);
      count = count + (cw - cwi);
      long long int csi = cs - i;
      if (f > (cs - i) * s) {
        long long int fi = f - (cs - i) * s;
        count = count + csi;
        long long int fcwi = fi / w;
        fcwi = min(fcwi, cwi);
        count = count + fcwi;
      } else {
        count = count + f / s;
      }
      maxi = max(maxi, count);
    }
    cout << maxi << endl;
  }
}
