#include using namespace std; const int maxn=200100,inf=2e9; int head[maxn],nxt[maxn],ver[maxn],cost[maxn],flow[maxn],tot=1; inline void addedge(int a,int b,int c,int d) { nxt[++tot]=head[a];ver[tot]=b;flow[tot]=c;cost[tot]=d;head[a]=tot; nxt[++tot]=head[b];ver[tot]=a;flow[tot]=0;cost[tot]=-d;head[b]=tot; } int S,T,dis[maxn],q[maxn],he,ta,inq[maxn],flv[maxn],lstv[maxn],lste[maxn]; inline bool myh_has_xuming() { for(int i=1;i<=T;i++) dis[i]=inf,inq[i]=0; dis[S]=0;q[he=ta=1]=S;flv[S]=inf; while(he<=ta) { int x=q[he++];inq[x]=0; for(int i=head[x];i;i=nxt[i]) { int y=ver[i];if(flow[i]==0||dis[y]<=dis[x]+cost[i]) continue; dis[y]=dis[x]+cost[i];flv[y]=min(flv[x],flow[i]); lstv[y]=x;lste[y]=i;if(!inq[y]) inq[q[++ta]=y]=1; } } return dis[T]>n>>a>>b>>c; memset(cnt,0,sizeof(cnt)); for(int i=1;i<=n;i++) { string s;cin>>s; if(s=="012") cnt[0]++; if(s=="021") cnt[1]++; if(s=="102") cnt[2]++; if(s=="120") cnt[3]++; if(s=="201") cnt[4]++; if(s=="210") cnt[5]++; } S=10;T=11; ans=0; for(int i=1;i<=T;i++) head[i]=0;tot=1; addedge(S,1,a,0); addedge(S,2,b,0); addedge(S,3,c,0); for(int i=0;i<6;i++) addedge(i+4,T,cnt[i],0); addedge(1,0+4,inf,-3); addedge(1,1+4,inf,-3); addedge(1,2+4,inf,-2); addedge(1,3+4,inf,-1); addedge(1,4+4,inf,-2); addedge(1,5+4,inf,-1); addedge(2,0+4,inf,-2); addedge(2,1+4,inf,-1); addedge(2,2+4,inf,-3); addedge(2,3+4,inf,-3); addedge(2,4+4,inf,-1); addedge(2,5+4,inf,-2); addedge(3,0+4,inf,-1); addedge(3,1+4,inf,-2); addedge(3,2+4,inf,-1); addedge(3,3+4,inf,-2); addedge(3,4+4,inf,-3); addedge(3,5+4,inf,-3); while(myh_has_xuming()) cut_it_off(); printf("%d\n",-ans); } int main() { int T;cin>>T; while(T--) solve(); return 0; }