#include #include #include #include #include #define Inf 233333 using namespace std; typedef long long ll; int Cntt[6]; int Head[55], Next[222], Go[222], Cap[222], Cost[222], Cnt = 1; void addedge(int x, int y, int z, int w) { Go[++Cnt] = y; Next[Cnt] = Head[x]; Head[x] = Cnt; Cap[Cnt] = z; Cost[Cnt] = w; } void addtwo(int x, int y, int z, int w) { addedge(x, y, z, w); addedge(y, x, 0, -w); } int Dis[55], Pre[55], Flow[55]; bool inque[55]; void SPFA() { memset(inque, 0, sizeof inque); memset(Dis, 63, sizeof Dis); memset(Pre, 0, sizeof Pre); memset(Flow, 0, sizeof Flow); Dis[1] = 0; inque[1] = 1; Flow[1] = Inf; vector V(0); V.push_back(1); for(int i = 0; i < V.size(); i++) { int x = V[i]; inque[x] = 0; for(int T = Head[x]; T; T = Next[T]) if(Cap[T]) { int dis = Dis[x] + Cost[T]; int c = min(Flow[x], Cap[T]); if(dis < Dis[Go[T]] || dis == Dis[Go[T]] && c > Flow[Go[T]]) { Dis[Go[T]] = dis; Flow[Go[T]] = c; Pre[Go[T]] = T ^ 1; if(!inque[Go[T]]) V.push_back(Go[T]); } } } } int flow() { int ans = 0; for(; ;) { SPFA(); if(!Flow[11]) return ans; ans += Flow[11] * Dis[11]; for(int i = 11; i != 1; i = Go[Pre[i]]) { Cap[Pre[i]] += Flow[11]; Cap[Pre[i] ^ 1] -= Flow[11]; } } } void Solve() { int n, a, b, c; scanf("%d%d%d%d", &n, &a, &b, &c); memset(Cntt, 0, sizeof Cntt); for(int i = 1; i <= n; i++) { char ch[4]; scanf("%s", ch); int ty = 0; if(ch[0] == '0') ty = (ch[1] == '2'); else if(ch[0] == '1') ty = 2 + (ch[1] == '2'); else ty = 4 + (ch[1] == '1'); Cntt[ty]++; } Cnt = 1; memset(Head, 0, sizeof Head); addtwo(1, 2, a, 0); addtwo(1, 3, b, 0); addtwo(1, 4, c, 0); addtwo(2, 5, Inf, -2); addtwo(3, 5, Inf, -1); addtwo(4, 5, Inf, -0); addtwo(2, 6, Inf, -2); addtwo(4, 6, Inf, -1); addtwo(3, 6, Inf, -0); addtwo(3, 7, Inf, -2); addtwo(2, 7, Inf, -1); addtwo(4, 7, Inf, -0); addtwo(3, 8, Inf, -2); addtwo(4, 8, Inf, -1); addtwo(2, 8, Inf, -0); addtwo(4, 9, Inf, -2); addtwo(2, 9, Inf, -1); addtwo(3, 9, Inf, -0); addtwo(4, 10, Inf, -2); addtwo(3, 10, Inf, -1); addtwo(2, 10, Inf, -0); addtwo(5, 11, Cntt[0], 0); addtwo(6, 11, Cntt[1], 0); addtwo(7, 11, Cntt[2], 0); addtwo(8, 11, Cntt[3], 0); addtwo(9, 11, Cntt[4], 0); addtwo(10, 11, Cntt[5], 0); printf("%d\n", -flow() + n); } int main() { int test; scanf("%d", &test); while(test--) { Solve(); } }