#include typedef int LL; typedef double dl; #define opt operator #define pb push_back const LL maxn=1e6+9,mod=998244353,inf=0x3f3f3f3f; LL Read(){ LL x(0),f(1); char c=getchar(); while(c<'0' || c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0' && c<='9'){ x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar(); }return x*f; } void Chkmin(LL &x,LL y){ if(yx) x=y; } LL add(LL x,LL y){ return x+=y,x>=mod?x-mod:x; } LL dec(LL x,LL y){ return x-=y,x<0?x+mod:x; } LL mul(LL x,LL y){ return 1ll*x*y%mod; } LL Do(LL x,LL y,LL z){ LL ans(inf); for(LL i=1;i<=std::min((1000+x-1)/x,(1000+y-1)/y);++i){ LL xx(1000-i*y),yy(1000-i*x); if(xx<=0 || yy<=0){ if(xx<=0 && yy<=0){ Chkmin(ans,i); }else if(xx<=0){ Chkmin(ans,i+std::min((yy+z-1)/z,(1000+y-1)/y)); }else if(yy<=0){ Chkmin(ans,i+std::min((xx+z-1)/z,(1000+x-1)/x)); } }else{ LL Tmp=(std::min((1000+x-1)/x,(xx+z-1)/z)); LL ret(i+Tmp); xx-=Tmp*z; LL zz(1000-Tmp*x); if(xx<=0 && zz<=0) Chkmin(ans,ret); else if(xx<=0){ Chkmin(ans,ret+std::min((zz+y-1)/y,(yy+z-1)/z)); }else{ Chkmin(ans,ret+std::min((xx+y-1)/y,(yy+x-1)/x)); } xx=1000-i*y,yy=1000-i*x; Tmp=(std::min((1000+y-1)/y,(yy+z-1)/z)); ret=(i+Tmp); yy-=Tmp*z; zz=(1000-Tmp*y); if(yy<=0 && zz<=0) Chkmin(ans,ret); else if(yy<=0){ Chkmin(ans,ret+std::min((zz+x-1)/x,(xx+z-1)/z)); }else{ Chkmin(ans,ret+std::min((xx+y-1)/y,(yy+x-1)/x)); } } } return ans; } int main(){ LL T=Read(); while(T--){ LL x(Read()),y(Read()),z(Read()),ans(inf); ans=std::min(Do(x,y,z),std::min(Do(x,z,y),Do(z,y,x))); printf("%d\n",ans); } return 0; }