#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int INF = LLONG_MAX;
const int N = 18;
void solve(int t) {
  long long int p, f;
  cin >> p >> f;
  long long int cnts, cntw;
  cin >> cnts >> cntw;
  long long int s, w;
  cin >> s >> w;
  long long int ans = 0;
  for (long long int i = 0; i <= cnts; i++) {
    long long int a1 = min(i, p / s);
    long long int a2 = min(cnts - i, f / s);
    long long int b1 = min(cntw, (p - a1 * s) / w);
    long long int b2 = min(cntw - b1, (f - a2 * s) / w);
    ans = max(ans, a1 + a2 + b1 + b2);
    b2 = min(cntw, (f - a2 * s) / w);
    b1 = min(cntw - b2, (p - a1 * s) / w);
    ans = max(ans, a1 + a2 + b1 + b2);
  }
  for (long long int i = 0; i <= cntw; i++) {
    long long int b1 = min(i, p / w);
    long long int b2 = min(cntw - i, f / w);
    long long int a1 = min(cnts, (p - b1 * w) / s);
    long long int a2 = min(cnts - a1, (f - b2 * w) / s);
    ans = max(ans, a1 + a2 + b1 + b2);
    a2 = min(cnts, (f - b2 * w) / s);
    a1 = min(cnts - a2, (p - b1 * w) / s);
    ans = max(ans, a1 + a2 + b1 + b2);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
}
