#include <cstdio>
#include <vector>

using namespace std;

const int N=100005;

int n;

struct Segment {
	int l,r,val1,val0;
	Segment(int l,int r,int val1,int val0) : l(l),r(r),val1(val1),val0(val0) {}
};

bool s1[N],s2[N],t1[N],t2[N];
vector<Segment>seg1,seg2;

void solve() {
	int ans=0;
	for(int i=1;i<=n;i++)
		if(!t1[i] && !t2[i])
			ans+=(s1[i]==s2[i]);
	
//	printf("%d\n",ans);		
	
	for(Segment &seg:seg1)
		for(int i=seg.l;i<=seg.r;i++)
			if(!t2[i]) {
				if(s2[i] && seg.val1) {
					seg.val1--;
					ans++;
				}
				if(!s2[i] && seg.val0) {
					seg.val0--;
					ans++;
				}
			}
	for(Segment &seg:seg2)
		for(int i=seg.l;i<=seg.r;i++)
			if(!t1[i]) {
				if(s1[i] && seg.val1) {
					seg.val1--;
					ans++;
				}
				if(!s1[i] && seg.val0) {
					seg.val0--;
					ans++;
				}
			}
	
//	printf("%d\n",ans);
	
	unsigned i,j;
	for(i=0,j=0;i<seg1.size() && j<seg2.size();i++) {
		while(seg1[i].l>seg2[j].r)
			j++;
		const int d1=min(seg1[i].val1,seg2[j].val1),d0=min(seg1[i].val0,seg2[j].val0);
		ans+=d1+d0;
		seg1[i].val1-=d1;
		seg1[i].val0-=d0;
		seg2[j].val1-=d1;
		seg2[j].val0-=d0;
	}
	i--;
	j++;
	while(j<seg2.size()) {
		const int d1=min(seg1[i].val1,seg2[j].val1),d0=min(seg1[i].val0,seg2[j].val0);
		ans+=d1+d0;
		seg1[i].val1-=d1;
		seg1[i].val0-=d0;
		seg2[j].val1-=d1;
		seg2[j].val0-=d0;
		j++;
	}

	printf("%d\n",ans);
}

int main() {
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);

	int T;
	scanf("%d",&T);
	while(T--) {
		seg1.clear();
		seg2.clear();
		scanf("%d",&n);
		getchar();
		char tmp;
		for(int i=1;i<=n;i++) {
			tmp=getchar();
			s1[i]=(tmp=='1');
		}
		getchar();
		for(int i=1;i<=n;i++) {
			tmp=getchar();
			s2[i]=(tmp=='1');
		}
		getchar();

		int len=0,val1=0;
		for(int i=1;i<=n;i++) {
			tmp=getchar();
			t1[i]=(tmp=='1');
			if(tmp=='0') {
				if(len>=1)
					seg1.push_back(Segment(i-len,i-1,val1,len-val1));
				len=val1=0;
			}
			else if(tmp=='1') {
				len++;
				val1+=s1[i];
			}
		}
		if(len>1)
			seg1.emplace_back(n-len+1,n,val1,len-val1);
		getchar();

		len=val1=0;
		for(int i=1;i<=n;i++) {
			tmp=getchar();
			t2[i]=(tmp=='1');
			if(tmp=='0') {
				if(len>=1)
					seg2.push_back(Segment(i-len,i-1,val1,len-val1));
				len=val1=0;
			}
			else if(tmp=='1') {
				len++;
				val1+=s2[i];
			}
		}
		
		if(len>1)
			seg2.emplace_back(n-len+1,n,val1,len-val1);

/*
		for(int i=1;i<=n;i++)
			putchar(s1[i]+'0');
		putchar('\n');
		for(int i=1;i<=n;i++)
			putchar(s2[i]+'0');
		putchar('\n');
		printf("%d\n",(int)seg1.size());
		for(auto x:seg1)
			printf("%d %d %d %d\n",x.l,x.r,x.val1,x.val0);
		printf("%d\n",(int)seg2.size());
		for(auto x:seg2)
			printf("%d %d %d %d\n",x.l,x.r,x.val1,x.val0);
*/

		solve();
	}
}
/*
1
20
11011101110001001000
00010010010010000100
11111110011111100111
01110011110011111101

*/

// I'm failing horribly at A.(10:18)
// 0pts,,,,,,,,,,,,,,,,,,,.........(10:52)
// I will bao4-ling2.(11:01)
// Look at my D.(11:37)
// I Lose.(12:56)
//
//

