#include<iostream>
#include<queue>
#include<cstdio>
#include<map>
#include<cstring>
#include<vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int maxn=2e5+45,MAXN=2e3+5,inf=0x3f3f3f3f;
const ll MOD=1e9+7;
//ll dp[maxn][maxn][maxn];
char s[maxn];
ll a[maxn],vis[10];
void work(ll p,ll f,ll cnts,ll cntw,ll s,ll w){//s表示剑重,cnts表示剑数
if(s>w){
swap(s,w);swap(cnts,cntw);
}
ll MAX=0,most=min(cnts,p/s);
for(int i=0;i<=most;i++){//i表示我拿了多少剑
ll axe_num1=(p-i*s)/w,sword_res=cnts-i;
if(sword_res*s>f){//若随从剩下的剑拿不下
MAX=max(MAX,i+axe_num1+f/s);
}
else{
ll axe_num2=(f-sword_res*s)/w;//随从还可以再拿多少斧子
ll axe=min(axe_num1+axe_num2,cntw);
MAX=max(MAX,cnts+axe);
}
}
cout<<MAX<<endl;
}
int main()
{
int t;
cin>>t;
while(t--){
ll p,f,cnts,cntw,s,w;
cin>>p>>f>>cnts>>cntw>>s>>w;
work(p,f,cnts,cntw,s,w);
}
return 0;
}