#include #include #include #include using namespace std; #define LL long long const int MX = 10000 + 233; int C[10] ,cnt[1 << 10]; int dp[6][1 << 10] ,n; int check(int x){ memset(dp ,0 ,sizeof dp); dp[0][0] = 1; for(int i = 1 ; i <= 5 ; ++i){ for(int j = 0 ; j < 1 << 10 ; ++j){ for(int S = j ; ; S = (S - 1) & j){ dp[i][j] |= dp[i - 1][S] && (n - cnt[j ^ S] <= x); if(!S) break; } } } int ok = 0; for(int i = 0 ; i < 1 << 10 && !ok ; ++i) ok |= dp[5][i]; return ok; } void solve(){ memset(C ,0 ,sizeof C); memset(cnt ,0 ,sizeof cnt); scanf("%d" ,&n); for(int i = 1 ; i <= n ; ++i){ char str[233]; scanf("%s" ,str); C[str[4] - '0']++; } for(int i = 0 ; i < 1 << 10 ; ++i){ for(int j = 0 ; j < 10 ; ++j){ if((i >> j) & 1) cnt[i] += C[j]; } } int l = 0 ,r = 10001 ,mid; while(l <= r){ mid = (l + r) >> 1; if(check(mid)) r = mid - 1; else l = mid + 1; } printf("%d\n" ,r + 1); } int main(){ int T; scanf("%d" ,&T); while(T--) solve(); return 0; }