#include #define mp make_pair #define fi first #define se second #define debug(x) cerr<<#x<<" = "<<(x)<void test(T x,Args... args){cerr< pii; typedef pair pll; const int MAXN=(int)1e5+10; const int MOD=(int)1e9+7; namespace MCMF{ const int oo=1e9; //无穷 const int mm=11111; //边 const int mn=5555; //点 int node,src,dest,edge; int ver[mm],flow[mm],cost[mm],nex[mm]; int head[mn],dis[mn],p[mn],q[mn],vis[mn]; void prepare(int _node,int _src,int _dest) //点数 起点 终点 { node=_node,src=_src,dest=_dest; for(int i=0; i=mn)?l=0:l) for(i=head[u=q[l]],vis[u]=0; i>=0; i=nex[i]) if(flow[i]&&dis[v=ver[i]]>(tmp=dis[u]+cost[i])) { dis[v]=tmp; p[v]=i^1; if(vis[v]) continue; vis[q[r++]=v]=1; if(r>=mn)r=0; } return p[dest]>-1; } int SpfaFlow() { int i,ret=0,delta; while(spfa()) { for(i=p[dest],delta=oo; i>=0; i=p[ver[i]]) if(flow[i^1]=0; i=p[ver[i]]) flow[i]+=delta,flow[i^1]-=delta; ret+=delta*dis[dest]; } return ret; } } vectorstr={"012","021","102","120","201","210"}; mapidx; int mark[10]; void Main(){ int n,a,b,c; memset(mark,0,sizeof mark); cin>>n>>a>>b>>c; for(int i=1;i<=n;i++){ string s; cin>>s; mark[idx[s]]++; } int S=0,T=1+3+str.size(); MCMF::prepare(T+1,S,T); vectorve={a,b,c}; for(int i=0;i<3;i++){ MCMF::addedge(S,i+1,ve[i],0); for(int j=1;j<=str.size();j++){ int val=3; for(auto c:str[j-1]){ if(c=='0'+i)break; val--; } /// test(i,str[j-1],val); MCMF::addedge(i+1,3+j,n,-val); } } for(int i=1;i<=str.size();i++){ MCMF::addedge(i+3,T,mark[i],0); } cout<<-MCMF::SpfaFlow()<<"\n"; } int main() { #ifdef BanFcc freopen("in.txt","r",stdin); #else ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #endif int cnt=0; for(auto s:str){ idx[s]=++cnt; } int T=1; cin>>T; for(int ca=1;ca<=T;ca++){ Main(); } return 0; }