#include using namespace std; typedef long long ll; int t[10],ans,f[6][1<<10]; int read(){ int res=0,op=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')op=-1;ch=getchar();} while(isdigit(ch))res=res*10+ch-'0',ch=getchar(); return res*op; } int get(){ int res;char ch=getchar(); while(!isdigit(ch))ch=getchar(); while(isdigit(ch)){res=ch;ch=getchar();} return res^48; } void write(ll x){ if(x<0)putchar('-'),x=-x; if(x>9)write(x/10); putchar(x%10+48); } int play(int x,int y){ int res=0; for(int i=0;i<=9;i++)if(((x>>i)&1)!=((y>>i)&1))res+=t[i]; return res; } void solve(){ int n=read(); memset(t,0,sizeof(t)); memset(f,0,sizeof(f)); for(int i=1;i<=n;i++)t[get()]++; f[0][0]=n; for(int i=1;i<=5;i++) for(int j=0;j<(1<<10);j++) for(int k=j;k<(1<<10);k=k+1|j) f[i][k]=max(f[i][k],min(f[i-1][j],play(j,k))); ans=0; for(int j=0;j<(1<<10);j++) ans=max(ans,f[5][j]); write(n-ans);puts(""); } int main() { int es=read(); while(es--) solve(); return 0; }