#include #include #include #include using namespace std; #define ll long long #define ge getchar #define pun putchar('\n') #define pu putchar #define puk putchar(' ') char c; int tt,m,cx,n,i,a[10],r[10]; ll g[50]; int sri(){c=ge();int x=0;while(c<'0')c=ge();while(c>='0')x=(x<<3)+(x<<1)+c-'0',c=ge();return x;} void ff(int i,int h){ if(i>9){ m=r[1];for(int j=2;j<=5;j++)if(r[j]cx)cx=m;return; } if(h<5)r[h+1]=a[i],ff(i+1,h+1),r[h+1]-=a[i]; for(int j=1;j<=h;j++)r[j]+=a[i],ff(i+1,h),r[j]-=a[i]; } void sc(ll x){int l=0;if(x==0)g[l=1]=0;while(x)g[++l]=x%10,x/=10;for(;l;l--)putchar(g[l]+'0');} int main(){ tt=sri(); while(tt--){ n=sri(); for(i=0;i<=9;i++)a[i]=r[i]=0; for(i=1;i<=n;i++){ c=ge();while(c<'0')c=ge(); ge();ge();ge();a[ge()-'0']++; c=ge(); }cx=0; ff(0,0); sc(n-cx);pun; } return 0; }