# include using namespace std; # define rep(i,a,n) for (int i=a; i<=n; ++i) # define per(i,a,n) for (int i=a; i>=n; --i) # define bug puts("H"); # define pb push_back # define mp make_pair # define all(x) (x).begin(), (x).end() # define SZ(x) (int)x.size() # define fi first # define se second # define lch p<<1,l,mid # define rch p<<1|1,mid+1,r # define mem(a,b) memset(a,b,sizeof(a)) # define INF 1000000001 # define MOD 1000000007 typedef vector Vi; typedef long long i64; typedef pair Pi; i64 powmod(i64 a, i64 b){i64 res=1;a%=MOD;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;} i64 Inv(i64 b){return powmod(b,(i64)MOD-2);} const int N = 20005; const double eps = 1e-9; int num[15]; char tmp[8]; int dp[6][1<<10]; int main () { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); mem(num,0); rep(i,1,n) scanf("%s", tmp), ++num[tmp[4]-'0']; int top = (1<<10); rep(i,1,5) rep(j,0,top-1) dp[i][j] = INF; rep(i,1,5) { rep(j,0,top-1) { for (int k = j; k; k = (k-1) & j) { int t = 0; rep(l,0,9) if (((k>>l)&1) == 0) t+=num[l]; dp[i][j] = min(dp[i][j], max(dp[i-1][j^k],t)); } dp[i][j] = min(dp[i][j], n); } } int ans = INF; rep(i,0,top-1) ans = min(ans, dp[5][i]); printf("%d\n", ans); } return 0; }