#include using namespace std; #define N 200007 #define INF 0x3f3f3f3f #define LL long long char s[10]; int a[10]; int b[5]; int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) { scanf(" %s", s); a[s[4] - '0']++; } sort(a, a + 10); int ans = 0; for (int i = 0; i < 390625; i++) { for (int j = 0; j < 5; j++) b[j] = 0; int x = i; for (int j = 0; j < 8; j++) { int y = x % 5; x /= 5; b[y] += a[j]; } b[0] += a[8]; b[1] += a[9]; x = 10000; for (int j = 0; j < 5; j++) x = min(x, b[j]); ans = max(ans, x); } printf("%d\n", n - ans); } return 0; }