#include using namespace std; typedef long long ll; typedef unsigned long long ull; #define Rep(i,a,b) for(register int i=(a);i<=(b);++i) #define rep(i,a,b) for(register int i=(a);i<(b);++i) #define Dep(i,a,b) for(register int i=(a);i>=(b);--i) #define mem(x,v) memset(x,v,sizeof(x)) #define gc getchar #define pc putchar const int inf = 0x3f3f3f3f; inline ll read(){ ll x = 0,f = 0;char c = gc(); for(;!isdigit(c);c=gc()) f|=(c=='-'); for(;isdigit(c);c=gc()) x = x * 10 + (c - '0'); return f ? -x : x; } inline void write(ll x){if(x < 0) pc('-'),x=-x;if(x>=10) write(x / 10);pc(x%10+'0');} inline void writeln(ll x){write(x),pc('\n');} inline void wri(ll x){write(x),pc(' ');} #define N 200 #define M 3000 const int maxn = 1e6+233; int n,cnt[2333]; char s[2333]; struct Edge{ int to,nxt,cap,cost; Edge(){} Edge(int to,int nxt,int cap,int cost):to(to),nxt(nxt),cap(cap),cost(cost){} }edge[2*M]; int first[N],nume,m; void Addedge(int a,int b,int cap,int cost){ edge[nume] = Edge(b,first[a],cap,cost);first[a] = nume++; edge[nume] = Edge(a,first[b],0,-cost);first[b] = nume++; } int dis[N],vis[N],pre[N]; int S,T; bool spfa(){ queue q; mem(dis,0x3f); mem(vis,false); mem(pre,-1); dis[S]=0; vis[S]=true; q.push(S); while(!q.empty()){ int u = q.front();q.pop(); vis[u] = false; for (int e=first[u];~e;e=edge[e].nxt){ int v = edge[e].to; if(edge[e].cap&&dis[v]>dis[u]+edge[e].cost){ dis[v]=dis[u]+edge[e].cost; pre[v] = e; if(!vis[v]){ q.push(v); vis[v]=true; } } } } return dis[T]!=inf; } int mcmf(){ int minflow,maxflow=0,mincost=0; while(spfa()){ minflow = inf; for(int i=pre[T];~i;i=pre[edge[i^1].to]) minflow = min(minflow,edge[i].cap); for(int i=pre[T];~i;i=pre[edge[i^1].to]) edge[i].cap -= minflow, edge[i^1].cap += minflow; mincost += minflow * dis[T]; maxflow += minflow; } return mincost; } int encode(char s[]){ return (s[0]-'0'+1)*100+(s[1]-'0'+1)*10+(s[2]-'0'+1); } void solve(){ int a,b,c; n = read(),a = read(),b = read(),c = read(); Rep(i,0,100) first[i] = -1;nume = 0; S=0,T=99; Addedge(S,1,a,0); Addedge(S,2,b,0); Addedge(S,3,c,0); Rep(i,1,3)Rep(j,1,3)Rep(k,1,3)cnt[i*100+j*10+k]=0; Rep(i,1,n){ scanf("%s",s); cnt[encode(s)]++; } int id=3; Rep(i,1,3)Rep(j,1,3)Rep(k,1,3)if(i!=j&&i!=k&&j!=k){ id++; Addedge(i,id,1000000,-3); Addedge(j,id,1000000,-2); Addedge(k,id,1000000,-1); Addedge(id,T,cnt[i*100+j*10+k],0); } writeln(-mcmf()); } int main(){ // freopen("1.in","r",stdin); int T = read(); while(T--) solve(); return 0; }