#include<bits/stdc++.h>
using namespace std;
int t , n;	
string nowa ;
string a , b , bm , am;
inline void solvea(int l , int r){
	if(l == r){
		return ;
	}
	int aa[2];
	memset(aa , 0 , sizeof(0));
	for(int i = l ;i <= r;i++){
		aa[a[i]-'0']++;
	}
	for(int i = l ;i <= r;i++){
		if(aa[b[i] - '0']){
			aa[b[i] - '0']--;
			nowa[i] = b[i];
		}else{
			aa[1 ^ (b[i] - '0')]--;
			nowa[i] = (1 ^ (b[i] - '0')) + '0';
		}
	}
	for(int i = l ;i <= r;i++){
		a[i] = nowa[i];
	}
	return ;
}	
string nowb ;
inline void solveb(int l , int r){

	if(l == r){
		return ;
	}
	int bb[2];
	memset(bb , 0 , sizeof(0));
	for(int i = l ;i <= r;i++){
		bb[b[i]-'0']++;
	}
	for(int i = l ;i <= r;i++){
		if(bb[a[i] - '0']){
			bb[a[i] - '0']--;
			nowb[i] = a[i];
		}else{
			bb[1 ^ (a[i] - '0')]--;
			nowb[i] = (1 ^ (a[i] - '0')) + '0';
		}
	}
	for(int i = l ;i <= r;i++){
		b[i] = nowb[i];
	}
	return ;
}
int main(){	
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin >> t;
	while(t--){
		cin >> n;
		int cnt = 0;
	 	cin >> a >> b >> am >> bm;		
	 	bool flag = 0;
	 	for(int i = 0 ;i < n;i++){
	 		if(am[i] == '0' && cnt == 0){
	 			cnt = 0;
	 			continue;
			 }
	 		if(am[i] == am[i - 1] && am[i] == '1' && i != n - 1){
	 			cnt++;
			 }else{
				 solvea(i - cnt - 1, i - 1);
				 cnt = 0;			 	
			 }
		 }
		cnt = 0;
	 	for(int i = 0 ;i < n;i++){
	 		if(bm[i] == bm[i - 1] && bm[i] == '1' && i != n - 1){
	 			cnt++;
			 }else{
				 solveb(i - cnt - 1, i - 1);	
				 cnt = 0;		 	
			 }
		 }
		 int sum = 0;
		 for(int i = 0 ;i < n;i++){
		 	if(a[i] == b[i]){
		 		sum++;
			 }
		 }
		 cout<<sum<<endl;
	}
	return 0;
}


