#include<bits/stdc++.h>
using namespace std;
int l,n;
char ch;
int a[100010],b[100010],cnt=1,ans;
struct node{
	int id,op;
}s1[100010],s[100010],t[100010],t1[100010];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>l;
	while(l--){
		ans=0;
		cnt=1;
		cin>>n;
		memset(s1,0,sizeof(s1));
		memset(s,0,sizeof(s));
		memset(t,0,sizeof(t));
		memset(t1,0,sizeof(t1));
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i=1;i<=n;i++){
			cin>>ch;
			if(ch=='1'){
				a[i]=1;
			}
			else{
				a[i]=0;
			}
		}
		for(int i=1;i<=n;i++){
			cin>>ch;
			if(ch=='1'){
				b[i]=1;
			}
			else{
				b[i]=0;
			}
		}
		for(int i=1;i<=n;i++){
			cin>>ch;
			if(ch=='1'){
				s[i].op=1;
				s[i].id=cnt;
				if(a[i]){
					t[cnt].id++;
				}
				else{
					t[cnt].op++;
				}
			}
			else{
				s[i].op=0;
				s[i].id=++cnt;
			}
		}
		cnt=1;
		for(int i=1;i<=n;i++){
			cin>>ch;
			if(ch=='1'){
				s1[i].op=1;
				s1[i].id=cnt;
				if(b[i]){
					t1[cnt].id++;
				}
				else{
					t1[cnt].op++;
				}
			}
			else{
				s1[i].op=0;
				s1[i].id=++cnt;
			}
		}
		for(int i=1;i<=n;i++){
			if((!s[i].op&&!s1[i].op)){
				if(a[i]==b[i])ans++;
				continue;
			}
			if(s[i].op&&s1[i].op){
				if(t[s[i].id].id&&t1[s1[i].id].id){
					ans++;
					t[s[i].id].id--;
					t1[s1[i].id].id--;
					continue;
				}
				if(t1[s1[i].id].op&&t[s[i].id].op){
					ans++;
					t[s[i].id].op--;
					t1[s1[i].id].op--;
					continue;
				}
				continue;
			}
			if(s[i].op&&!s1[i].op){
				if(b[i]&&t[s[i].id].id){
					ans++;
					t[s[i].id].id--;
					continue;
				}
				if(!b[i]&&t[s[i].id].op){
					ans++;
					t[s[i].id].op--;
					continue;
				}
				continue;
			}
			if(s1[i].op&&!s[i].op){
				if(a[i]&&t1[s1[i].id].id){
					ans++;
					t1[s1[i].id].id--;
					continue;
				}
				if(!a[i]&&t1[s1[i].id].op){
					ans++;
					t1[s1[i].id].op--;
					continue;
				}
				continue;
			}
		}
		cout<<ans<<endl;
	}
}

