#include using namespace std; int ans, n, t; int cnt[10], sum[5]; inline void dfs(int x, int y) { if (x == 10) { int now = 1e9; for (int i = 0; i < 5; i++) now = min(now, sum[i]); ans = max(ans, now); return; } for (int i = 0; i < y; i++) sum[i] += cnt[x], dfs(x + 1, y), sum[i] -= cnt[x]; if (y != 5) sum[y] += cnt[x], dfs(x + 1, y + 1), sum[y] -= cnt[x]; } int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); memset(cnt, 0, sizeof cnt); for (int i = 1; i <= n; i++) { char a[10]; scanf("%s", a); cnt[a[strlen(a) - 1] - '0']++; } ans = 0; dfs(0, 0); printf("%d\n", n - ans); } }