#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int p, f, n1, n2, w1, w2;
    cin >> p >> f >> n1 >> n2 >> w1 >> w2;
    if (w1 > w2) {
      swap(w1, w2);
      swap(n1, n2);
    }
    long long int x, y, ans = 0, res = 0;
    for (long long int i = 0; i <= n1; i++) {
      if (i * w1 <= p) {
        y = min(n2, (p - i * w1) / w2);
        ans = i + y;
        x = min(n1 - i, f / w1);
        y = min(n2 - y, (f - x * w1) / w2);
        ans += x + y;
      }
      if (ans > res) res = ans;
    }
    cout << res << "\n";
  }
}
