#include #include #include #include #define RI register int using namespace std; int cnt[15]; int sum[1 << 10]; int f[6][1 << 10]; char s[15]; int main() { //freopen("a.in", "r", stdin); int T; scanf("%d", &T); while (T--) { memset(cnt, 0, sizeof(cnt)); memset(sum, 0, sizeof(sum)); memset(f, 0, sizeof(f)); int n; scanf("%d", &n); for (RI i = 1; i <= n; ++i) { scanf("%s", s + 1); ++cnt[s[5] - '0']; } int all = 1 << 10; for (RI i = 0; i < all; ++i) for (RI j = 0; j < 10; ++j) if ((i >> j) & 1) sum[i] += cnt[j]; f[0][0] = 0x3f3f3f3f; for (RI i = 1; i <= 5; ++i) for (RI s1 = 0; s1 < all; ++s1) for (RI s2 = 0; s2 < all; ++s2) if ((s1 & s2) == 0) f[i][s1 | s2] = max(f[i][s1 | s2], min(f[i - 1][s1], sum[s2])); printf("%d\n", n - f[5][all - 1]); } return 0; }