#include #include #include #include #include using namespace std; int T, n; char s[10]; int cnt[15]; int suff[15]; int total[10]; int ans; void Init() { memset(cnt, 0, sizeof(cnt)); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", s); int num = s[4] - '0'; cnt[num]++; } suff[10] = 0; for (int i = 9; i >= 0; i--) suff[i] = suff[i + 1] + cnt[i]; for (int i = 1; i <= 5; i++) total[i] = n; } void Dfs(int x) { if (x > 9) { int res = 0; for (int i = 1; i <= 5; i++) { res = max(res, total[i]); } ans = min(ans, res); return; } pair tmp = make_pair(0, 0); for (int week = 1; week <= 5; week++) { if (total[week] > ans) { tmp.first += total[week]; tmp.second++; } } if (tmp.first - suff[x] > ans * tmp.second) return; if (cnt[x] == 0) Dfs(x + 1); else { for (int week = 1; week <= 5; week++) { total[week] -= cnt[x]; Dfs(x + 1); total[week] += cnt[x]; } } } void Solve() { ans = n; Dfs(0); printf("%d\n", ans); } int main() { scanf("%d", &T); for (int cas = 1; cas <= T; cas++) { Init(); Solve(); } return 0; }