#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define pb push_back #define mp make_pair typedef pair pii; typedef long long ll; typedef double ld; typedef vector vi; #define fi first #define se second #define fe first #define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);} #define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);} #define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);} #define es(x,e) (int e=fst[x];e;e=nxt[e]) #define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e]) const int MOD=1e9+7; #define SZ 666666 int main() { int T,x,y,z; cin>>T; while(T--) { cin>>x>>y>>z; int ans=2e9; auto wo=[&]() { for(int i=0;i*x<1000;++i) { int j=1000-i*x; j=j/y+bool(j%y); assert(j&&i*x+(j-1)*y<1000&&i*x+j*y>=1000); if(max(i-1,j-1)*z>=1000) continue; int h1=1000-i*z,h2=1000-j*z; //(h1,x) (h2,y) int t1=h1/y+bool(h1%y), t2=h2/x+bool(h2%x); if(h1<=0) t1=0; if(h2<=0) t2=0; ans=min(ans,min(t1,t2)+i+j); } }; wo(); swap(x,y); swap(y,z); wo(); swap(x,y); swap(y,z); wo(); swap(x,y); swap(y,z); swap(x,y); wo(); swap(x,y); swap(y,z); wo(); swap(x,y); swap(y,z); wo(); swap(x,y); swap(y,z); printf("%d\n",ans); } }