#include using namespace std; char s[10]; int T, n, a[10], l, r, m, sum[1 << 10], cnt[1 << 10], b[1 << 10][1 << 10]; bool f[6][1 << 10]; bool check(int m) { memset(f, 0, sizeof(f)); memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < 1 << 10; ++i) { f[0][i] = 1; for (int j = 0; j < 1 << 10; ++j) if (!(i & j) && n - sum[j] <= m) b[i][cnt[i]++] = j; } for (int i = 1; i <= 5; ++i) for (int j = 0; j < 1 << 10; ++j) for (int k = 0; k < cnt[j] && !f[i][j]; ++k) f[i][j] = f[i - 1][j | b[j][k]]; for (int i = 0; i < 1 << 10; ++i) if (f[5][i]) return 1; return 0; } int main() { scanf("%d", &T); while (T--) { scanf("%d", &n); memset(a, 0, sizeof(a)); for (int i = 0; i < n; ++i) { scanf("%s", s); ++a[s[4] - '0']; } for (int i = 0; i < 1 << 10; ++i) { sum[i] = 0; for (int j = 0; j < 10; ++j) if (i & 1 << j) sum[i] += a[j]; } l = 1; r = n; while (l < r) { m = (l + r) / 2; if (check(m)) r = m; else l = m + 1; } printf("%d\n", l); } return 0; }