#include using namespace std; char buf[10]; int sum[20], sss[1 << 10]; int dp[10][1 << 10]; int dfs(int now, int mask) { if (now == 0) return 0; if (~dp[now][mask]) return dp[now][mask]; int &res = dp[now][mask] = max(sss[(1 << 10) - 1], dfs(now - 1, mask)); for (int mmm = mask; mmm; mmm = mmm - 1 & mask) { int maxj = max(sss[((1 << 10) - 1) ^ mmm], dfs(now - 1, mask ^ mmm)); res = min(res, maxj); } return res; } int main () { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); memset(sum, 0, sizeof(sum)); for (int i = 0; i < n; i++) { scanf("%s", buf); sum[buf[4] - '0']++; } for (int i = 1; i < (1 << 10); i++) { sss[i] = 0; for (int j = 0; j < 10; j++) { if (i >> j & 1) sss[i] += sum[j]; } } memset(dp, -1, sizeof(dp)); printf("%d\n", dfs(5, (1 << 10) - 1)); } return 0; }