#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
string s1,s2,t1,t2;
int cnt1[maxn],cnt2[maxn]; //count 1 in s1,s2
int t,n,ans;
struct haha{
	int pre;
	int nxt;
};
vector<haha> v1,v2;
vector<string> gen;

void init(){
	ans = 0;
	memset(cnt1,0,sizeof(cnt1));
	memset(cnt2,0,sizeof(cnt2));
	v1.clear();
	v2.clear();
	return ;
}

void dfs(int x,string s){
	if(x == n){
		gen.push_back(s);
		return ;
	}
	dfs(x + 1, s + '0');
	dfs(x + 1, s + '1');

	return ;
}

void solve1(){
	int pos1 = 1;
	int pos2 = 1;
	haha x;
	for(int i = 1;i <= n; i++){
		if(t1[i] == '0' && t1[i-1] != '0'){
			x.pre = pos1;
			x.nxt = i - 1;
			v1.push_back(x);
		}
		if(t1[i] != '0' && t1[i-1] == '0'){
			pos1 = i;
		}
		if(t2[i] == '0' && t2[i-1] != '0'){
			haha x;
			x.pre = pos2;
			x.nxt = i - 1;
			v2.push_back(x);
		}
		if(t2[i] != '0' && t2[i-1] == '0'){
			pos2 = i;
		}
	}
	if(t1[n] != '0'){
		x.pre = pos1;
		x.nxt = n;
		v1.push_back(x);
	}
	if(t2[n] != '0'){
		x.pre = pos2;
		x.nxt = n;
		v2.push_back(x);
	}
	dfs(0,"");
	for(auto s : gen){
		s = " " + s;
		bool f = true;
		for(haha h : v1){
			int y = 0;
			for(int i = h.pre; i <= h.nxt; i++){
				y += s[i] - '0';
			}
			if(y != cnt1[h.nxt] - cnt1[h.pre - 1]){
				f = false;
				break;
			}
		}
		for(int i = 1; i <= n; i++){
			if(t1[i] == '0' && s[i] != s1[i]){
				f = false;
				break;
			}
		}
		if(f == false){
			continue;
		}
		cout << s << endl; 
		for(auto ss : gen){
			f = true;
			ss = " " + ss;
			for(haha h : v2){
				int y = 0;
				for(int i = h.pre; i <= h.nxt; i++){
					y += ss[i] - '0';
				}
				if(y != cnt2[h.nxt] - cnt2[h.pre - 1]){
					f = false;
					break;
				}
			}
			for(int i = 1; i <= n; i++){
				if(t2[i] == '0' && ss[i] != s2[i]){
					f = false;
					break;
				}
			}
			if(f == false){
				continue;
			}
			int ans1 = 0;
			for(int i = 1; i <= n; i++){
				if(s[i] == ss[i]){
					ans1++;
				}
			}
			ans = max(ans,ans1);
		}
	}
	cout << ans << endl;
	return ;
}

void solveA(){
	for(int i = 1; i <= n; i++){
		if(s1[i] == s2[i]){
			ans ++;
		}
	} 
	cout << ans << endl;
	return ; 
}

void solveB(){
	int pos1 = 1;
	haha x;
	for(int i = 1;i <= n; i++){
		if(t1[i] == '0' && t1[i-1] != '0'){
			x.pre = pos1;
			x.nxt = i - 1;
			v1.push_back(x);
		}
		if(t1[i] != '0' && t1[i-1] == '0'){
			pos1 = i;
		}
	}
	if(t1[n] != '0'){
		x.pre = pos1;
		x.nxt = n;
		v1.push_back(x);
	}
	for(auto h : v1){
		ans += h.nxt - h.pre + 1 - abs((cnt1[h.nxt] - cnt1[h.pre-1]) - (cnt2[h.nxt] - cnt2[h.pre-1])); 
	}
	for(int i = 1; i <= n; i++){
		if(t1[i] == '0'){
			if(s1[i] == s2[i]){
				ans++;
			}
		}
	}
	cout << ans << endl;
	return ;
} 

void solveC(){
	int pos1,pos2;
	int i,j,x,y;
	for(i = 1; i <= n; i++){
		if(t1[i] == '0'){
			pos1 = i;
		}
		if(t2[i] == '0'){
			pos2 = i;
		}
	}
	if(pos1 < pos2){
		swap(s1,s2);
		swap(t1,t2);
		swap(pos1,pos2);
		swap(cnt1,cnt2);
	}
	i = cnt1[pos1-1];
	int ii = pos1 - 1 - i;
	j = cnt1[n] - cnt1[pos1 - 1];
	int jj = n - pos1 + 1 - j;
	x = cnt2[pos2];
	int xx = pos2 - x;
	y = cnt2[n] - cnt2[pos2];
	int yy = n - pos2 - y;
	if(i >= x){
		ans += x;
		i-= x;
		x = 0;
		if(ii >= xx){
			ans += xx;
			ii -= xx;
			xx = 0;
		}else{
			ans += ii;
			ii = 0;
		}
		ans += min(i+j,y);
		ans += min(jj + ii, yy);
	}else{
		ans += i;
		x -= i;
		i = 0;
		ii -= xx;
		ans += min(j,y);
		ans += min(ii + jj,yy);
	}
	cout << ans << endl;
	return ;
}



int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin >> t;
	while(t--){
		init();
		cin >> n;
		cin >> s1 >> s2 >> t1 >> t2;
		s1 = " " + s1;
		s2 = " " + s2;
		t1 = " " + t1;
		t2 = " " + t2;
		int xx = 0; 
		int xxx = 0;
		for(int i = 1; i <= n; i++){
			cnt1[i] = cnt1[i-1] + s1[i] - '0';
			cnt2[i] = cnt2[i-1] + s2[i] - '0';
			xx += t1[i] - '0';
			xxx += t2[i] - '0';
		}
		if(cnt1[n] == n || cnt1[n] == 0){
			solveA();
		}else{
			if(t1 == t2){
				solveB();
			}else{
				if(xx ==  n - 1 && xxx == n - 1){
					solveC();
				}else{
					solve1();
				}
			}	
		}	
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
} 
