/* * Author: Kewth * Date: echo -n ' ' && date +%Y.%m.%d # Type "!!sh" in Vim. * Solution: To be updated after "Accept". * Digression: * CopyRight: %%%%%%%%%%% %%%% %%%% %% %%━━■%% %% %% %% %%% %% % %% %% % %%%%■% %% %%% %% %%% %%%%%%%%%%%%%%■%% %%%%%% */ #include #include #include #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long ll; static struct { inline operator int () { int x; return scanf("%d", &x), x; } inline operator ll () { ll x; return scanf("%lld", &x), x; } template inline void operator () (T &x) { x = *this; } template inline void operator () (T &x, A &...a) { x = *this; this -> operator () (a...); } } read; const int maxn = 100005; char s[maxn][5]; int tot[3][3]; int main () { int T = read; while (T -- ) { int n = read, a = read, b = read, c = read, A = 0, B = 0, C = 0; memset(tot, 0, sizeof tot); for (int i = 1; i <= n; i ++) { scanf("%s", s[i]); if (s[i][0] == '0') ++ A; if (s[i][0] == '1') ++ B; if (s[i][0] == '2') ++ C; ++ tot[s[i][0] - '0'][s[i][1] - '0']; } int ans = n + (std::min(a, A) + std::min(b, B) + std::min(c, C)) * 2; int aa = a > A, bb = b > B, cc = c > C; if (aa + bb + cc == 0) ; if (aa + bb + cc == 1) { if (aa) ans += std::min(tot[1][0], B - b) + std::min(tot[2][0], C - c); if (bb) ans += std::min(tot[0][1], A - a) + std::min(tot[2][1], C - c); if (cc) ans += std::min(tot[0][2], A - a) + std::min(tot[1][2], B - b); } if (aa + bb + cc == 2) { if (!aa) ans += std::min(tot[0][1], b - B) + std::min(tot[0][2], c - C); if (!bb) ans += std::min(tot[1][0], a - A) + std::min(tot[1][2], c - C); if (!cc) ans += std::min(tot[2][0], a - A) + std::min(tot[2][1], b - B); } /* if (aa + bb + cc == 3) */ /* return 1; */ printf("%d\n", ans); } }