#include <bits/stdc++.h>
using namespace std;
struct TreeNode {
  int val;
  TreeNode* left;
  TreeNode* right;
  TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
struct ListNode {
  int val;
  ListNode* next;
  ListNode(int x) : val(x), next(NULL) {}
};
int nxt() {
  int x;
  cin >> x;
  return x;
}
long long nxtLong() {
  long long x;
  cin >> x;
  return x;
}
string nxtStr() {
  string x;
  cin >> x;
  return x;
}
char nxtChar() {
  char x;
  cin >> x;
  return x;
}
double nxtDouble() {
  double x;
  cin >> x;
  return x;
}
long double nxtLDouble() {
  long double x;
  cin >> x;
  return x;
}
TreeNode* makeTree(int n) {
  queue<TreeNode*> tree_nodes;
  TreeNode* root;
  if (n) {
    root = new TreeNode(nxt());
    tree_nodes.push(root);
  } else {
    return NULL;
  }
  while (!tree_nodes.empty()) {
    TreeNode* node = tree_nodes.front();
    tree_nodes.pop();
    bool left;
    cin >> left;
    if (left) {
      node->left = new TreeNode(nxt());
      tree_nodes.push(node->left);
    }
    bool right;
    cin >> right;
    if (right) {
      node->right = new TreeNode(nxt());
      tree_nodes.push(node->right);
    }
  }
  return root;
}
ListNode* makeLinkedList(int n) {
  ListNode* list = new ListNode(0);
  ListNode* dummy = list;
  for (int i = 0; i < n; ++i) {
    list->next = new ListNode(nxt());
    list = list->next;
  }
  return dummy->next;
}
void solve() {
  long long p = nxtLong(), f = nxtLong();
  long long cnts = nxtLong(), cntw = nxtLong();
  long long s = nxtLong(), w = nxtLong();
  long long x, y, a, b;
  if (s <= w) {
    x = cnts, y = cntw;
    a = s, b = w;
  } else {
    x = cntw, y = cnts;
    a = w, b = s;
  }
  long long ma = LLONG_MIN;
  for (int i = 0; i <= x; ++i) {
    long long wt = i * a;
    long long tot = 0;
    long long np = p, nf = f;
    long long aa = x, bb = y;
    if (wt <= np) {
      np -= wt;
      tot += i;
    }
    tot += min(np / b, bb);
    bb -= min(np / b, bb);
    tot += min((aa - i), nf / a);
    nf -= (min((aa - i), nf / a) * a);
    tot += min(nf / b, bb);
    ma = max(ma, tot);
  }
  cout << ma << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(9);
  int t = nxt();
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}
