#include <bits/stdc++.h>
using namespace std;
void solve();
string conc(long long int a, long long int b) {
  return to_string(a) + "|" + to_string(b);
}
long long int rev(long long int x) {
  long long int ans = 0;
  while (x != 0) {
    ans = ans * 10 + (x % 10);
    x /= 10;
  }
  return ans;
}
long long int numdig(long long int x) {
  long long int ans = 0;
  while (x != 0) {
    ans++;
    x /= 10;
  }
  return ans;
}
void printvec(vector<long long int> &v) {
  for (long long int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void printmat(vector<vector<long long int>> &mat) {
  for (long long int i = 0; i < mat.size(); i++) {
    for (long long int j = 0; j < mat[0].size(); j++) cout << mat[i][j] << " ";
    cout << "\n";
  }
}
void solve() {
  long long int p, f, ct0, ct1, wt0, wt1;
  vector<long long int> ct(2), wt(2);
  cin >> p >> f >> ct0 >> ct1 >> wt0 >> wt1;
  long long int ans = 0;
  ct[0] = ct0;
  ct[1] = ct1;
  wt[0] = wt0;
  wt[1] = wt1;
  if (wt[0] > wt[1]) {
    swap(wt[0], wt[1]);
    swap(ct[0], ct[1]);
  }
  for (long long int hm1 = 0; hm1 <= ct[0]; hm1++) {
    if (hm1 * wt[0] > p) break;
    long long int pleft = p - wt[0] * hm1;
    long long int hm2 = min(ct[1], pleft / wt[1]);
    long long int sl = ct[0] - hm1, wl = ct[1] - hm2;
    long long int hm3 = min(sl, f / wt[0]);
    long long int fleft = f - hm3 * wt[0];
    long long int hm4 = min(wl, fleft / wt[1]);
    ans = max(ans, hm1 + hm2 + hm3 + hm4);
  }
  cout << ans << "\n";
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
