/* * Author: Kewth * Date: echo -n ' ' && date +%Y.%m.%d # Type "!!sh" in Vim. * Solution: To be updated after "Accept". * Digression: * CopyRight: %%%%%%%%%%% %%%% %%%% %% %%━━■%% %% %% %% %%% %% % %% %% % %%%%■% %% %%% %% %%% %%%%%%%%%%%%%%■%% %%%%%% */ #include #include #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long ll; static struct { inline operator int () { int x; return scanf("%d", &x), x; } inline operator ll () { ll x; return scanf("%lld", &x), x; } template inline void operator () (T &x) { x = *this; } template inline void operator () (T &x, A &...a) { x = *this; this -> operator () (a...); } } read; const int maxn = 10005; char s[10]; int tot[10]; int sum[5]; int ans; void force (int x) { if (x == 10) { int min = 1000000000; for (int i = 0; i < 5; i ++) min = std::min(min, sum[i]); ans = std::max(ans, min); return; } for (int i = 0; i < 5 and i <= x; i ++) { sum[i] += tot[x]; force(x + 1); sum[i] -= tot[x]; } } int main () { int T = read; while (T --) { int n = read, Tot = 0; for (int x = 0; x < 10; x ++) tot[x] = 0; for (int i = 1; i <= n; i ++) scanf("%s", s), ++ tot[s[4] - '0'], ++ Tot; ans = 0; force(0); printf("%d\n", Tot - ans); } }