#include //#include //#include //#include //#include //#include //#include //#include //#include //#include //#include //#include #define X first #define Y second #define PB push_back #define MP make_pair #define EB emplace_back #define mset(var,val) memset(var,val,sizeof(var)) #define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0) #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) //using namespace __gnu_pbds; //using namespace __gnu_cxx; using namespace std; namespace ___ { #ifdef local #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0) void err() { cout << endl; } template class T, typename t, typename... Args> void err(T a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); } template void err(T a, Args... args) { cout << a << ' '; err(args...); } #else #define dbg(...) #endif //#ifdef local //typedef long long LL; //#else //typedef __int128 LL; //#endif // local int _ = 0; void testcase() { cout << "Case " << (++_) << ": "; } } template inline bool scan(T&ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-' and (c<'0' or c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0' and c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } template inline void out(T x) { if(x>9) out(x/10); putchar(x%10+'0'); } using namespace ___; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair pii; typedef pair pll; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos(-1.0); const double eps = 1e-6; const int mod = 998244353; const int lim = 1e3; const int N = 2e6+10; const int M = 1e6+10; #define lson (rt<<1) #define rson (rt<<1|1) ll qpow(ll a, ll b) { ll ans = 1; for(;b;b>>=1){ if(b&1) ans = ans*a%mod; a=a*a%mod; } return ans; } int dp[2][1050]; int a[1050]; int b[10]; char s[10]; const int mx = 1<<10; void work(){ int n; cin >> n; mset(b,0); rep(i,n){ cin >> s; b[s[4]-'0']++; } int cur = 0, pre = 1; rep(msk,mx) { a[msk] = n; rep(i,10) { if (msk>>i&1) { a[msk] -=b[i]; } } dp[cur][msk] = a[msk]; } rep(i,4) { swap(pre,cur); rep(curmsk, mx) { dp[cur][curmsk] = n; rep(premsk, mx) { if ((curmsk & premsk) == premsk) { dp[cur][curmsk] = min(dp[cur][curmsk], max(a[curmsk^premsk], dp[pre][premsk])); } } } } int ans = n; rep(msk,mx) { ans = min(ans, dp[cur][msk]); } cout << ans << "\n"; } int main() { #ifdef local freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); #endif // local IOS; // init(); int t; cin>>t; // for(; t--;) work(); // return 0; }