#pragma comment(linker, "/STACK:1024000000,1024000000") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug() puts("++++") #define print(x) cout<<(x)< P; const int INF = 0x3f3f3f3f; const LL LNF = 1e17; const double inf = 1e20; const double PI = acos(-1.0); const double eps = 1e-8; const int maxn = 300 + 7; const int maxm = 2000000 + 7; const LL mod = 1e9 + 7; const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1}; const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1}; int n, m; inline bool is_in(int r, int c) { return r >= 0 && r < n && c >= 0 && c < m; } inline int readInt(){ int x; scanf("%d", &x); return x; } struct Edge{ int from, to, cap, flow; LL cost; }; struct MCMF{ int n, m; vector edges; vector G[maxn]; int inq[maxn]; LL d[maxn]; int p[maxn]; int a[maxn]; void init(int n){ this->n = n; for(int i = 0; i < n; ++i) G[i].clear(); edges.clear(); } void addEdge(int from, int to, int cap, LL cost){ edges.push_back((Edge){from, to, cap, 0, cost}); edges.push_back((Edge){to, from, 0, 0, -cost}); m = edges.size(); G[from].push_back(m-2); G[to].push_back(m-1); } bool BellmanFord(int s, int t, int &flow, LL &cost){ for(int i = 0; i < n; ++i) d[i] = INF; memset(inq, 0, sizeof inq); d[s] = 0; inq[s] = 1; p[s] = 0; a[s] = INF; queue q; q.push(s); while(!q.empty()){ int u = q.front(); q.pop(); inq[u] = 0; for(int i = 0; i < G[u].size(); ++i){ Edge &e = edges[G[u][i]]; if(e.cap > e.flow && d[e.to] > d[u] + e.cost){ d[e.to] = d[u] + e.cost; p[e.to] = G[u][i]; a[e.to] = min(a[u], e.cap-e.flow); if(!inq[e.to]) q.push(e.to), inq[e.to] = 1; } } } if(d[t] == INF) return false; flow += a[t]; cost += d[t] * a[t]; int u = t; while(u != s){ edges[p[u]].flow += a[t]; edges[p[u]^1].flow -= a[t]; u = edges[p[u]].from; } return true; } LL minCost(int s, int t){ int flow = 0; LL cost = 0; while(BellmanFord(s, t, flow, cost)); return cost; } }; MCMF mcmf; unordered_map mp; int main(){ int T; scanf("%d", &T); while(T--){ scanf("%d", &n); int a, b, c; mp.cl; mcmf.init(300); scanf("%d %d %d", &a, &b, &c); for(int i = 0; i < n; ++i){ scanf("%d", &m); ++mp[m]; } int s = 5, t = 280; for(auto &it : mp){ mcmf.addEdge(s, it.fi, it.se, 0); int x = it.fi; for(int i = 1; i <= 3; ++i, x /= 10){ mcmf.addEdge(it.fi, x % 10, it.se, -i); } } mcmf.addEdge(0, t, a, 0); mcmf.addEdge(1, t, b, 0); mcmf.addEdge(2, t, c, 0); printf("%lld\n", -mcmf.minCost(s, t)); } return 0; }