#include using namespace std; const int maxn = 1010, maxm = 110, inf = 0x3f3f3f3f, maxnode = 2010; const string tr[6] = {"012", "021", "102", "120", "201", "210"}; int n, m, s[maxn * 2], s_cnt, node_cnt; struct Edge { int to, cap, flow, cost, rev; Edge(int to, int cap, int cost, int rev): to(to), cap(cap), flow(0), cost(cost), rev(rev) {} }; vector graph[maxnode]; int dis[maxnode], st, ed; bool in_que[maxnode], in_stk[maxnode]; queue que; void AddEdge(int from, int to, int cap, int cost) { graph[from].push_back(Edge(to, cap, cost, graph[to].size())); graph[to].push_back(Edge(from, 0, -cost, graph[from].size() - 1)); } void init() { for (int i = 1; i <= node_cnt; ++i) graph[i].clear(); } bool Spfa() { for (int i = 1; i <= node_cnt; ++i) dis[i] = i == st ? 0 : inf; que.push(st); while (!que.empty()) { int p = que.front(); que.pop(); in_que[p] = 0; for (int i = 0; i < (int)graph[p].size(); ++i) { Edge e = graph[p][i]; if (e.cap > e.flow && dis[p] + e.cost < dis[e.to]) { dis[e.to] = dis[p] + e.cost; if (!in_que[e.to]) { in_que[e.to] = true; que.push(e.to); } } } } return dis[ed] < inf; } int Dfs(int p, int a) { if (p == ed) return a; in_stk[p] = true; int ans = 0, now; for (int i = 0; i < (int)graph[p].size(); ++i) { Edge &e = graph[p][i]; if (e.cap > e.flow && !in_stk[e.to] && dis[p] + e.cost == dis[e.to]) { now = Dfs(e.to, min(a, e.cap - e.flow)); ans += now; a -= now; e.flow += now; graph[e.to][e.rev].flow -= now; if (!a) break; } } in_stk[p] = false; return ans; } int MinCostMaxFlow() { int ans = 0; while (Spfa()) ans += dis[ed] * Dfs(st, inf); return ans; } int cnt[6], t, a, b, c; int main() { scanf("%d", &t); while (t--) { scanf("%d%d%d%d", &n, &a, &b, &c); init(); node_cnt = 11; AddEdge(1, 3, a, 0); AddEdge(1, 4, b, 0); AddEdge(1, 5, c, 0); memset(cnt, 0, sizeof cnt); for (int i = 1; i <= n; ++i) { string s; cin >> s; for (int j = 0; j < 6; ++j) if (tr[j] == s) ++cnt[j]; } for (int i = 0; i < 6; ++i) { AddEdge(i + 6, 2, cnt[i], 0); for (int k = 0; k < 3; ++k) AddEdge(tr[i][k] - '0' + 3, i + 6, inf, -(3 - k)); } st = 1; ed = 2; printf("%d\n", -MinCostMaxFlow()); } }