#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int base = 31337;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;
int t;
int main() {
  scanf("%d", &t);
  while (t--) {
    int a, b;
    scanf("%d%d", &a, &b);
    int x, y;
    int wx, wy;
    scanf("%d%d%d%d", &x, &y, &wx, &wy);
    if (a > b) swap(a, b);
    if (wx > wy) {
      swap(x, y);
      swap(wx, wy);
    }
    int sol = 0;
    for (int i = 0; i * wx <= a && i <= x; i++) {
      int pb = min(y, (a - i * wx) / wy);
      int pc = min(x - i, b / wx);
      int pd = min(y - pb, (b - pc * wx) / wy);
      sol = max(sol, i + pb + pc + pd);
    }
    printf("%d\n", sol);
  }
  return 0;
}
