#include using namespace std; typedef long long ll; typedef pair pii; #define fir first #define sec second #define rep(i,a,b) for (int i = (a); i <= (b); ++ i) #define rrp(i,a,b) for (int i = (a); i >= (b); -- i) #define gc() getchar() template inline void read(tp& x) { x = 0; char tmp; bool key = 0; for (tmp = gc(); !isdigit(tmp); tmp = gc()) key = (tmp == '-'); for (; isdigit(tmp); tmp = gc()) x = (x << 3) + (x << 1) + (tmp ^ '0'); if (key) x = -x; } template inline void ckmn(tp& x,tp y) { x = x < y ? x : y; } template inline void ckmx(tp& x,tp y) { x = x < y ? y : x; } int n, num[10]; bool dp[10][1 << 10]; bool check(int lim) { memset(dp, 0, sizeof dp); dp[0][0] = true; rep (i, 1, 5) { rep (j, 0, (1 << 10) - 1) if (dp[i-1][j]) { int t = ((1 << 10) - 1) ^ j; for (int s = t; true; s = (s - 1) & t) { int tmp = n; rep (a, 0, 9) if ((s >> a)&1) tmp -= num[a]; if (tmp <= lim) dp[i][j | s] = true; if (s == 0) break; } } } rep (j, 0, (1 << 10) - 1) if (dp[5][j]) return true; return false; } void solve() { read(n); memset(num, 0, sizeof num); string tmp; rep (i, 1, n) { cin >> tmp; int t = (int)tmp.size()-1; ++ num[tmp[t] - '0']; } int l = 1, r = n, ans = n; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) r = mid - 1, ans = mid; else l = mid + 1; } printf("%d\n", ans); } int main() { int T; read(T); while (T --) solve(); return 0; }