#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int p, f;
    cin >> p >> f;
    int cs, cw;
    cin >> cs >> cw;
    int s, w;
    cin >> s >> w;
    int ans = 0;
    for (int i = 0; i <= cs; i++) {
      if (i * s > p) break;
      int rem = p - i * s;
      int ret = rem / w;
      ret = min(cw, ret);
      if (s <= w) {
        int can = f / s;
        can = min(can, cs - i);
        int rem2 = f - can * s;
        ans = max(ans, i + ret + can + min(rem2 / w, cw - ret));
      } else {
        int can = f / w;
        can = min(can, cw - ret);
        int rem2 = f - can * w;
        ans = max(ans, i + ret + can + min(rem2 / s, cs - i));
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
