#include <bits/stdc++.h>
using namespace std;
bool check(long long int mid, long long int num1, long long int min,
           long long int a, long long int b, long long int max) {
  if (mid <= num1) {
    return (a / min + b / min) >= mid;
  } else {
    for (int i = 0; i <= num1; i++) {
      long long int j = a - i * min;
      long long int k = b - (num1 - i) * min;
      if (j < 0 || k < 0) {
        continue;
      }
      if ((j / max + k / max) >= (mid - num1)) {
        return true;
      }
    }
  }
  return false;
}
int main() {
  int n;
  while (cin >> n) {
    long long int a, b, c, d, e, f;
    while (cin >> a >> b >> c >> d >> e >> f) {
      long long int lb = 0;
      long long int ub = c + d + 1;
      long long int min, max;
      long long int num1, num2;
      if (f >= e) {
        min = e;
        num1 = c;
        max = f;
        num2 = d;
      } else if (f < e) {
        min = f;
        num1 = d;
        max = e;
        num2 = c;
      }
      while (ub - lb > 1) {
        long long int mid = (ub + lb) / 2;
        if (check(mid, num1, min, a, b, max)) {
          lb = mid;
        } else {
          ub = mid;
        }
      }
      cout << lb << "\n";
    }
  }
}
