#include using namespace std; #define il inline #define rg register #define int long long il int read() { int re=0,k=1;char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')k=-1;ch=getchar();} while(ch<='9'&&ch>='0'){re=re*10+ch-48;ch=getchar();} return re*k; } il void write(int x) { if(x<0)return putchar('-'),write(-x),void(); if(x<10)return putchar(x+48),void(); return write(x/10),write(x%10),void(); } int t[15],a[100005],g[6],s; /* int find(int x) { if(x==fa[x])return x; return fa[x]=find(fa[x]); } int merge(int u,int v) { u=find(u);v=find(v); fa[u]=v; return v; }*/ void dfs(int x) { if(x>9) { int t=0x3f3f3f3f; for(int i=1;i<=5;i++) t=min(t,g[i]); s=max(t,s); return; } for(int i=1;i<=5;i++) { g[i]+=t[x]; dfs(x+1); g[i]-=t[x]; } } signed main() { int T=read(); while(T--) { memset(t,0,sizeof(t));s=0; memset(g,0,sizeof(g)); int n=read(); for(int i=1;i<=n;i++) { a[i]=read(); t[a[i]%10]++; } dfs(0); write(n-s); puts(""); } }