#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  long long P, F, cs, cw, S, W, ans;
  while (t--) {
    cin >> P >> F;
    cin >> cs >> cw;
    cin >> S >> W;
    ans = 0;
    long long n, n1, n2;
    long long sum = min(P / S, cs);
    for (long long i = 0; i <= sum; i++) {
      n = (P - i * S) / W;
      n = min(n, cw);
      if (S < W) {
        if (F >= (cs - i) * S) {
          n1 = cs - i;
          n2 = (F - (cs - i) * S) / W;
          n2 = min(n2, cw - n);
        } else
          n1 = F / S, n2 = 0;
      } else {
        if (F >= (cw - n) * W) {
          n1 = cw - n;
          n2 = (F - (cw - n) * W) / S;
          n2 = min(n2, cs - i);
        } else
          n1 = F / W, n2 = 0;
      }
      long long k = i + n + n1 + n2;
      ans = max(ans, k);
    }
    cout << ans << endl;
  }
  return 0;
}
