#include<bits/stdc++.h>
#include "testlib.h"
using namespace std;
using ll=long long;
int main(int argc, char* argv[])
{
	registerTestlibCmd(argc, argv);
	int t=inf.readInt();
	ll score=0;
	for(int _=1;_<=t;_++)
	{
		int n=inf.readInt();
		vector<ll>a(n+1);
		for(int i=1;i<=n;i++)a[i]=inf.readInt();
		pattern pat("[01]{"+to_string(n)+"}");
		string oufs=ouf.readToken(pat);
		string anss=ans.readToken(pat);
		vector<ll>ansb,ansc;
		vector<ll>oufb,oufc;
		anss='?'+anss,oufs='?'+oufs;
		for(int i=1;i<=n;i++)if(anss[i]=='0')ansb.push_back(a[i]);else ansc.push_back(a[i]);
		sort(ansb.begin(),ansb.end());
		sort(ansc.begin(),ansc.end());
		ll l1=0,l2=0;
		if(ansb.size()<2)l1=2e9+1;
		else l1=ansb[0]+ansb[1];
		if(ansc.size()<2)l2=2e9+1;
		else l2=ansc[0]+ansc[1];
		l1=min(l1,l2);
		
		ll r1=0,r2=0;
		for(int i=1;i<=n;i++)if(oufs[i]=='0')oufb.push_back(a[i]);else oufc.push_back(a[i]);
		sort(oufb.begin(),oufb.end());
		sort(oufc.begin(),oufc.end());
		if(oufb.size()<2)r1=2e9+1;
		else r1=oufb[0]+oufb[1];
		if(oufc.size()<2)r2=2e9+1;
		else r2=oufc[0]+oufc[1];
		r1=min(r1,r2);
		
		if(r1<l1)quitf(_wa,"Wrong answer on test %d , jans is %lld, pans is %lld!",_,l1,r1);
		score+=l1;
	}
	quitf(_ok,"%d tests ok, your score is %lld!",t,score);
}
