#include <cstdio>
#include <iostream>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
char temp;
void getline(char line[],int count){
	line[count]=0;
	temp=getchar();
	for(int i=0;i<count;i++){
		line[i]=getchar();
	}
}
int run_count;
int str_length;
void xchg(char str[],int a,int b){
	temp=str[a];
	str[a]=str[b];
	str[b]=temp;
}
int max_chance = 0;
int last_chance = 0;
bool new_chance(int chance,int deep,char s1[],char s2[]){
	if(chance>max_chance){
		max_chance=chance;
	} else {
		last_chance++;
		if(last_chance>1000){
			return true;
		}
	}
	return false;
}
bool solve(int deep,char s1[],char s2[],char t1[],char t2[]){
	int chance = 0;
	for(int i=0;i<str_length;i++){
		if(s1[i]==s2[i]){
			chance++;
		}
	}
	bool brk=new_chance(chance,deep,s1,s2);
	if(brk){
		return brk;
	}
	for(int i=0;i<str_length;i++){
		if(s1[i]==s2[i]){
		} else {
			if(t1[i]=='1'){
				for(int j=0;j<i;j++){
					if(t1[j]=='1'){
						xchg(s1,i,j);
						if(s1[i]==s2[i]){
							solve(deep+1,s1,s2,t1,t2);
						}
						xchg(s1,i,j);
					}
				}
				for(int j=i;j<str_length-1;j++){
					if(t1[j]=='1'){
						xchg(s1,i,j);
						if(s1[i]==s2[i]){
							solve(deep+1,s1,s2,t1,t2);
						}
						xchg(s1,i,j);
					}
				}
			}
		}
	}
	for(int i=0;i<str_length;i++){
		if(s1[i]==s2[i]){
		} else {
			if(t2[i]=='1'){
				for(int j=0;j<i;j++){
					if(t2[j]=='1'){
						xchg(s2,i,j);
						if(s1[i]==s2[i]){
							solve(deep+1,s1,s2,t1,t2);
						}
						xchg(s2,i,j);
					}
				}
				for(int j=i;j<str_length-1;j++){
					if(t2[j]=='1'){
						xchg(s2,i,j);
						if(s1[i]==s2[i]){
							solve(deep+1,s1,s2,t1,t2);
						}
						xchg(s2,i,j);
					}
				}
			}
		}
	}
	return false;
}
int main() {
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&run_count);
	for(;run_count>0;run_count--){
		scanf("%d",&str_length);
		char s1[str_length+1];
		char s2[str_length+1];
		char t1[str_length+1];
		char t2[str_length+1];
		getline(s1,str_length);
		getline(s2,str_length);
		getline(t1,str_length);
		getline(t2,str_length);
		solve(1,s1,s2,t1,t2);
		cout<<max_chance;
	}
	return 0;
}
