#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=1e5+1e3;
char s[6][maxn];
int n;
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		for(int i=1;i<=4;i++){
			int j=0;
			char ch=getchar();
			while(ch!='0'&&ch!='1') ch=getchar();
			while(ch=='0'||ch=='1'){
				++j;
				s[i][j]=ch;
				if(j>=n) break;
				ch=getchar();
			}
		}
		s[1][n+1]=0;s[2][n+1]=0;
		s[3][n+1]=0;s[4][n+1]=0;
		int i=1,j=1,cnt1=0,cnt2=0;
		int ans=0,n1=0,n0=0,duode0=0;
		int lasti=0,lastj=0;
		while(i<=n&&j<=n){
			while(s[3][i]!='0'&&i<=n){
				if(s[1][i]=='1'&&i!=lasti) cnt1++;
				i++;
			}if(i==n+1) i=n;
			while(s[4][j]!='0'&&j<=n){
				if(s[2][j]=='1'&&j!=lastj) cnt2++;
				j++;
			}if(j==n+1) j=n;
			if(i==j){
				if(s[1][i]==s[2][j]){
					if(s[1][i]=='1') n1++;
					else duode0++;
					ans++;
				}
				ans+=min(cnt1,cnt2);
				n1+=min(cnt1,cnt2);
				lasti=i;lastj=j;
				i++;j++;
				cnt1=0;cnt2=0;
				if(i>n) break;
			}
			else if(i>j){
				int chak=j-lasti-1;
				if(cnt1<=cnt2){
					if(chak>=cnt1){
						ans+=cnt1;
						n1+=cnt1;
						cnt1=0;
					}
					else{
						ans+=chak;
						n1+=chak;
						cnt1-=chak;
					}
				}
				else{
					if(chak>=cnt2){
						ans+=cnt2;
						n1+=cnt2;
						cnt1-=cnt2;
					}
					else{
						ans+=chak;
						n1+=chak;
						cnt1-=chak;
					}
				}
				if(cnt1&&s[2][j]=='1'){
					ans++;
					n1++;
					cnt1--;
				}
				lastj=j;
				j++;
				cnt2=0;
			}
			else{
				int chak=i-lastj-1;
				if(cnt2<=cnt1){
					if(chak>=cnt2){
						ans+=cnt2;
						n1+=cnt2;
						cnt2=0;
					}
					else{
						ans+=chak;
						n1+=chak;
						cnt2-=chak;
					}
				}
				else{
					if(chak>=cnt1){
						ans+=cnt1;
						n1+=cnt1;
						cnt2-=cnt1;
					}
					else{
						ans+=chak;
						n1+=chak;
						cnt2-=chak;
					}
				}
				if(cnt2&&s[1][i]=='1'){
					ans++;
					n1++;
					cnt2--;
				}
				lasti=i;
				i++;
				cnt1=0;
			}
		}
		cnt1=0;cnt2=0;
		for(i=1;i<=n;i++){
			if(s[1][i]=='1') cnt1++;
			if(s[2][i]=='1') cnt1++;
		}
		n0=n+n1-cnt1;
		ans=n0+n1;
//		printf("ans=%d n=%d n1=%d n0=%d cnt1=%d duode0=%d\n",ans,n,n1,n0,cnt1,duode0);
//		ans=ans+n0-duode0;
		printf("%d\n",ans);
//		printf("%d\n",n0+n1);
	}
	return 0;
}
