#include #include #include #include #define RI register int using namespace std; int vis[15], cnt[15]; int const MAXN = 100005; char s[MAXN][10]; int l[MAXN][10]; int main() { //freopen("a.in", "r", stdin); int T; scanf("%d", &T); while (T--) { int n, a, b, c; scanf("%d %d %d %d", &n, &a, &b, &c); for (RI i = 1; i <= n; ++i) { scanf("%s", s[i]); l[i][0] = s[i][0] - '0'; l[i][1] = s[i][1] - '0'; l[i][2] = s[i][2] - '0'; } cnt[0] = cnt[1] = cnt[2] = 0; vis[0] = vis[1] = vis[2] = 0; for (RI i = 1; i <= n; ++i) ++cnt[l[i][0]]; if (cnt[0] <= a) vis[0] = 1; if (cnt[1] <= b) vis[1] = 1; if (cnt[2] <= c) vis[2] = 1; int ans = 0; if (vis[0]) ans += cnt[0] * 2, a -= cnt[0]; else ans += a * 2, cnt[0] -= a, a = 0; if (vis[1]) ans += cnt[1] * 2, b -= cnt[1]; else ans += b * 2, cnt[1] -= b, b = 0; if (vis[2]) ans += cnt[2] * 2, c -= cnt[2]; else ans += c * 2, cnt[2] -= c, c = 0; for (RI i = 1; i <= n; ++i) { if (!vis[l[i][0]]) { if (l[i][1] == 0 && a && cnt[l[i][0]]) ans += 1, --a, --cnt[l[i][0]]; if (l[i][1] == 1 && b && cnt[l[i][0]]) ans += 1, --b, --cnt[l[i][0]]; if (l[i][1] == 2 && c && cnt[l[i][0]]) ans += 1, --c, --cnt[l[i][0]]; } } printf("%d\n", ans + n); } return 0; }