#include <bits/stdc++.h>
using namespace std;
long long N, T, P, F, num1, num2, A1, A2;
void open() {
  if (fopen("aa.inp", "r")) {
    freopen("aa.inp", "r", stdin);
    freopen("aa.out", "w", stdout);
  }
}
void solve() {
  cin >> T;
  while (T--) {
    cin >> P >> F;
    cin >> num1 >> num2;
    cin >> A1 >> A2;
    if (A1 > A2) {
      swap(A1, A2);
      swap(num1, num2);
    }
    long long res = 0;
    for (long long i = 0; i <= num1; ++i) {
      if (i * A1 > P) break;
      long long j = min(num2, (P - i * A1) / A2);
      long long sum1 = i + j;
      num1 -= i, num2 -= j;
      long long sum3 = min(num1, F / A1);
      long long sum2 = sum3 + min(num2, (F - sum3 * A1) / A2);
      res = max(res, sum1 + sum2);
      num1 += i, num2 += j;
    }
    cout << res << '\n';
  }
}
int main() {
  open();
  solve();
  return 0;
}
