#include // {{{ Definitions #define reg register #define pr std::pair #define fi first #define se second #define FIN(s) freopen(s, "r", stdin) #define FOUT(s) freopen(s, "w", stdout) #define FERR(s) freopen(s, "w", stderr) #define debug(...) fprintf(stderr, __VA_ARGS__) #define dputs(s) fprintf(stderr, s"\n") #define rep(i, l, r) for (int i = l; i <= r; ++i) #define lep(i, l, r) for (int i = l; i < r; ++i) #define irep(i, r, l) for (int i = r; i >= l; --i) #define ilep(i, r, l) for (int i = r; i > l; --i) #define Rep(i, n) rep(i, 1, n) #define Lep(i, n) lep(i, 1, n) #define IRep(i, n) irep(i, n, 1) #define ILep(i, n) ilep(i, n, 1) typedef long long ll; typedef long double ld; // }}} // {{{ Modular namespace modular { const int MOD = 1000000007; inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; } inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; } inline int mul(int x, int y) { return 1LL * x * y % MOD; } inline int qpow(int x, int y) { int ans = 1; for (; y; y >>= 1, x = mul(x, x)) if (y & 1) ans = mul(ans, x); return ans; } }; // namespace modular // }}} // {{{ Base namespace Base { template inline Tp input() { Tp x = 0, y = 1; char c = getchar(); while ((c < '0' || '9' < c) && c != EOF) { if (c == '-') y = -1; c = getchar(); } if (c == EOF) return 0; while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar(); return x *= y; } template inline void read(Tp &x) { x = input(); } template inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; } template inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; } }; // namespace Base // }}} using namespace Base; int N; int f[10][2000], c[11]; char s[10]; void solve() { read(N); memset(c, 0, sizeof(c)); Rep(i, N) { scanf("%s", s + 1); c[s[5] - '0']++; } memset(f, 127, sizeof(f)); int mx = f[1][1], val; f[0][0] = 0; Rep(i, 5) { rep(j, 0, 1023) if ((val = f[i - 1][j]) < mx) { int j2 = 1023 ^ j, t = 0; for (int k = j2; k; k = (k - 1) & j2) { t = 0; lep(p, 0, 10) if (k >> p & 1) t += c[p]; chmin(f[i][k | j], std::max(val, N - t)); } } } printf("%d\n", std::min(N, f[5][1023])); } int main() { #ifndef ONLINE_JUDGE FIN("a.in"); // FOUT("a.out"); // FERR("a.log"); #endif int T = input(); while (T--) solve(); return 0; }