#include #define ctz __builtin_ctz using std::cin; using std::cout; typedef long long ll; typedef std::vector vector; int n; int c[10], f[6][1024]; inline void up(int &x, const int y) {x < y ? x = y : 0;} void work() { int i, j, k; char s[10]; cin >> n, memset(c, 0, 40); for (i = 0; i < n; ++i) cin >> s, ++c[s[4] & 15]; for (*f[1] = i = 0; i <= 1023; ++i) f[1][i] = f[1][i & (i - 1)] + c[ctz(i)]; for (i = 2; i <= 5; ++i) for (j = 0; j <= 1023; ++j) for (f[i][j] = 0, k = j; ; k = (k - 1) & j) { up(f[i][j], std::min(f[i - 1][j ^ k], f[1][k])); if (!k) break; } cout << n - f[5][1023] << '\n'; } int main() { int T; std::ios::sync_with_stdio(false), cin.tie(NULL); for (cin >> T; T; --T) work(); return 0; }