#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5; 
typedef pair<bool,int> pbi;
int n;
string s[2],t[2];
namespace slv1{
	int rge[N];
	void solve(){
		memset(rge,0,sizeof(rge));
		int now=0,cnt=0;
		for(int i=0;i<n;++i){
			int j;
			++cnt;
			for(j=i;j<n;){
				int x=t[now][j]-'0',y=t[now][j+1]-'0',z=t[now^1][j]-'0';
				rge[j]=cnt;
				if(x){
					if(y==x) ++j;
					else if(z==x && t[now^1][j+1]=='1'){
						now^=1;
						++j;
					}
					else break;
				}
				else break;
			}
			i=j;
		}
		stack <pbi> st;
		int ans=0;
		for(int i=0;i<n;++i){
			int x=s[0][i]-'0',y=s[1][i]-'0';
			if(x!=y){
				bool fl;int pos;
				if(!st.empty()){
					tie(fl,pos)=st.top();
					if(rge[pos]!=rge[i])
						st.pop();
					else if(rge[pos]==rge[i] && fl==(!x)){
						st.pop();
						ans+=2;
					}
					else st.push({x,i}); 
				}
				else st.push({x,i});
			}
			else ans++;
		} 
		cout<<ans<<'\n';
	}
}
namespace slv2{
	void solve(){
		int ans=0;
		for(int i=0;i<(1<<(n-1));++i){
			for(int j=0;j<(1<<(n-1));++j){
				bool fl=0;
				for(int k=0;k<(n-1);++k){
					if(i&(1<<k) && (t[0][k]!='1' || t[0][k+1]!='1')){
						fl=1;
						break;
					}
					if(j&(1<<k) && (t[1][k]!='1' || t[1][k+1]!='1')){
						fl=1;
						break;
					}
				}
				if(!fl){
					string s1=s[0],s2=s[1];
					int cnt=0;
					for(int k=0;k<(n-1);++k){
						if(i&(1<<k))
							swap(s1[k],s1[k+1]);
						if(j&(1<<k))
							swap(s2[k],s2[k+1]);
					}
					//cout<<s1<<' '<<s2<<'\n';
					for(int k=0;k<n;++k)
						if(s1[k]==s2[k])
							++cnt;
					//if(cnt==6) cout<<s1<<' '<<s2<<'\n';
					ans=max(ans,cnt);
				}
			}
		}
		cout<<ans<<'\n';
	}
}
namespace slv3{
	int rge[N];
	void solve(){
		memset(rge,0,sizeof(rge));
		int now=1,cnt=0;
		for(int i=0;i<n;++i){
			int j;
			++cnt;
			for(j=i;j<n;){
				int x=t[now][j]-'0',y=t[now][j+1]-'0';
				rge[j]=cnt;
				if(x){
					if(y==x) ++j;
					else break;
				}
				else break;
			}
			i=j;
		}
		stack <pbi> st;
		int ans=0;
		for(int i=0;i<n;++i){
			int x=s[0][i]-'0',y=s[1][i]-'0';
			if(x!=y){
				bool fl;int pos;
				if(!st.empty()){
					tie(fl,pos)=st.top();
					if(rge[pos]!=rge[i])
						st.pop();
					else if(rge[pos]==rge[i] && fl==(!y)){
						st.pop();
						ans+=2;
					}
					else st.push({y,i}); 
				}
				else st.push({y,i});
			}
			else ans++;
		}
		cout<<ans<<'\n'; 
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	cin>>T;
	while(T--){
		cin>>n;
		cin>>s[0]>>s[1]>>t[0]>>t[1];
		if(s[0].find('0')==s[0].npos || s[0].find('1')==s[0].npos)
			slv3::solve();
		else if(n<=10)
			slv2::solve();
		else slv1::solve();
	}
	return 0;
}




