#include using namespace std; #define N 200007 #define INF 0x3f3f3f3f #define LL long long const int MAX_N = 20; const int MAX_M = 200; const int inf = 0x3f3f3f3f; struct edge { int v, c, w, next; } e[MAX_M]; int p[MAX_N], s, t, eid; void init() { memset(p, -1, sizeof(p)); eid = 0; } void insert(int u, int v, int c, int w) { e[eid].v = v; e[eid].c = c; e[eid].w = w; e[eid].next = p[u]; p[u] = eid++; } void addedge(int u, int v, int w, int c) { insert(u, v, c, w); insert(v, u, 0, -w); } bool vis[MAX_N]; int d[MAX_N]; int pre[MAX_N]; bool spfa() { memset(vis, 0, sizeof(vis)); memset(d, 0x3f, sizeof(d)); memset(pre, -1, sizeof(pre)); d[s] = 0; vis[s] = true; queue q; q.push(s); while (!q.empty()) { int u = q.front(); q.pop(); vis[u] = false; for (int i = p[u]; i != -1; i = e[i].next) { if (e[i].c) { int v = e[i].v; if (d[u] + e[i].w < d[v]) { d[v] = d[u] + e[i].w; pre[v] = i; if (!vis[v]) { q.push(v); vis[v] = true; } } } } } return pre[t] != -1; } int costflow() { int ans = 0; int ret = 0; while(spfa()) { int flow = inf; for(int i = t; i != s; i = e[pre[i]^1].v) { flow = min(e[pre[i]].c, flow); ans += flow; } for(int i = t; i != s; i = e[pre[i]^1].v) { e[pre[i]].c -= flow; e[pre[i]^1].c += flow; ret += e[pre[i]].w * flow; } } return ret; } char str[10]; int A[6]; int main() { int T; scanf("%d", &T); while (T--) { init(); int n, a, b, c; scanf("%d%d%d%d", &n, &a, &b, &c); memset(A, 0, sizeof(A)); for (int i = 0; i < n; i++) { scanf(" %s", str); if (str[0] == '0' && str[1] == '1') A[0]++; else if (str[0] == '0' && str[1] == '2') A[1]++; else if (str[0] == '1' && str[1] == '0') A[2]++; else if (str[0] == '1' && str[1] == '2') A[3]++; else if (str[0] == '2' && str[1] == '0') A[4]++; else if (str[0] == '2' && str[1] == '1') A[5]++; } for (int i = 0; i < 6; i++) { addedge(1, i + 2, 0, A[i]); //printf("%d\n", A[i]); } addedge(2, 8, -3, n); addedge(2, 9, -2, n); addedge(2, 10, -1, n); addedge(3, 8, -3, n); addedge(3, 9, -1, n); addedge(3, 10, -2, n); addedge(4, 8, -2, n); addedge(4, 9, -3, n); addedge(4, 10, -1, n); addedge(5, 8, -1, n); addedge(5, 9, -3, n); addedge(5, 10, -2, n); addedge(6, 8, -2, n); addedge(6, 9, -1, n); addedge(6, 10, -3, n); addedge(7, 8, -1, n); addedge(7, 9, -2, n); addedge(7, 10, -3, n); addedge(8, 11, 0, a); addedge(9, 11, 0, b); addedge(10, 11, 0, c); s = 1, t = 11; printf("%d\n", -costflow()); } return 0; }