/* - - - - - - - - - - - - - - - User : VanishD problem : [bzoj2597] Points : min flow - - - - - - - - - - - - - - - */ # include # define ll long long # define inf 0x3f3f3f3f # define NN 110 # define N 10010 # define M 1000100 using namespace std; template void read(T &x){ x = 0; int fh = 1; double num = 1.0; char ch = getchar(); while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); } while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); } if (ch == '.'){ ch = getchar(); while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();} } x = x * fh; } struct Edge{ int data, next, l, re, vote; }e[M]; int head[N], use[N], dis[N], q[N], mn[N], frm[N], place; void build(int u, int v, int l, int w){ e[++place].data = v; e[place].next = head[u]; head[u] = place; e[place].vote = w; e[place].l = l; e[place].re = place + 1; e[++place].data = u; e[place].next = head[v]; head[v] = place; e[place].vote = -w; e[place].l = 0; e[place].re = place - 1; } void spfa(int S, int T){ memset(use, 0, sizeof(use)); memset(dis, inf, sizeof(dis)); int pl = 1, pr = 1; q[1] = S; use[S] = true; mn[S] = inf; dis[S] = 0; while (pl <= pr){ int x = q[(pl++) % N]; for (int ed = head[x]; ed != 0; ed = e[ed].next) if (dis[e[ed].data] > dis[x] + e[ed].vote && e[ed].l != 0){ dis[e[ed].data] = dis[x] + e[ed].vote; mn[e[ed].data] = min(e[ed].l, mn[x]); frm[e[ed].data] = ed; if (use[e[ed].data] == false){ use[e[ed].data] = true; q[(++pr) % N] = e[ed].data; } } use[x] = false; } } void change(int S, int T){ int tmp = mn[T]; while (T != S){ e[frm[T]].l -= tmp; e[e[frm[T]].re].l += tmp; T = e[e[frm[T]].re].data; } } int F(int S, int T){ int sum = 0, num = 0; for (spfa(S, T); dis[T] != inf; spfa(S, T)){ sum = sum + dis[T] * mn[T]; num = num + mn[T]; change(S, T); } return sum; } int cnt[6]; char s[10]; int main(){ // freopen("bzoj2597.in", "r", stdin); // freopen("bzoj2597.out", "w", stdout); // freopen("T5.in", "r", stdin); // freopen("T5.out", "w", stdout); int oT; read(oT); int S = 4, T = 5; while (oT--){ memset(head, 0, sizeof(head)); place = 0; int a, b, c, n; read(n); read(a); read(b); read(c); memset(cnt, 0, sizeof(cnt)); for (int i = 1; i <= n; i++){ scanf("\n%s", s); if (s[0] == '0' && s[1] == '1' && s[2] == '2') cnt[0]++; if (s[0] == '0' && s[1] == '2' && s[2] == '1') cnt[1]++; if (s[0] == '1' && s[1] == '0' && s[2] == '2') cnt[2]++; if (s[0] == '1' && s[1] == '2' && s[2] == '0') cnt[3]++; if (s[0] == '2' && s[1] == '0' && s[2] == '1') cnt[4]++; if (s[0] == '2' && s[1] == '1' && s[2] == '0') cnt[5]++; } if (cnt[0] + cnt[1] > a) build(S, 1, cnt[0] + cnt[1] - a, 0); else build(1, T, a - cnt[0] - cnt[1], 0); if (cnt[2] + cnt[3] > b) build(S, 2, cnt[2] + cnt[3] - b, 0); else build(2, T, b - cnt[2] - cnt[3], 0); if (cnt[4] + cnt[5] > c) build(S, 3, cnt[4] + cnt[5] - c, 0); else build(3, T, c - cnt[4] - cnt[5], 0); build(6, 2, cnt[0], 1); build(7, 3, cnt[1], 1); build(6, 3, cnt[0], 2); build(7, 2, cnt[1], 2); build(8, 1, cnt[2], 1); build(9, 3, cnt[3], 1); build(8, 3, cnt[2], 2); build(9, 1, cnt[3], 2); build(10, 1, cnt[4], 1); build(11, 2, cnt[5], 1); build(10, 2, cnt[4], 2); build(11, 1, cnt[5], 2); build(1, 6, cnt[0], 0); build(1, 7, cnt[1], 0); build(2, 8, cnt[2], 0); build(2, 9, cnt[3], 0); build(3, 10, cnt[4], 0); build(3, 11, cnt[5], 0); int ans = 3 * n - F(S, T); cout << ans << endl; } return 0; }