#include <bits/stdc++.h>
using namespace std;
constexpr int N=1e5+2;
using P=pair<int,int>;
int n;char s[2][N],t[2][N];
void init(){
	cin>>n>>s[0]>>s[1]>>t[0]>>t[1];
}
queue<P> q[2];
P operator-(const P &a,const P &b){
	return {a.first-b.first,a.second-b.second};
}
void solve(){
	int ans=0;
	for (int i=0;i<2;i++){
		P cnt={0,0};
		for (int j=0,lst=t[i][0];;j++){
			if ((t[i][j]!='1'||lst!=t[i][j])&&j)
				q[i].push(cnt),cnt={0,0},lst=t[i][j];
			if (j==n)break;
			if (s[i][j]^'0')
				cnt.second++;
			else
				cnt.first++;
		}
	}
//	for (int i=0;i<2;i++,cout<<'\n')
//	while (!q[i].empty())
//		cout<<'('<<q[i].front().first<<','<<q[i].front().second<<')'<<' ',q[i].pop();
	P ta={0,0},tb={0,0};
	while (!q[0].empty()||!q[1].empty()){
		if (ta.first==0&&ta.second==0)
			ta=q[0].front(),q[0].pop();
//			,cout<<"!a\n"<<flush
		if (tb.first==0&&tb.second==0)
			tb=q[1].front(),q[1].pop();
//			,cout<<"!b\n"<<flush
//		cout<<'('<<ta.first<<','<<ta.second<<')'<<' '<<'('<<tb.first<<','<<tb.second<<')'<<'\n'<<std::flush;
		P same={min(ta.first,tb.first),min(ta.second,tb.second)};
		ta=ta-same,tb=tb-same;ans+=same.first+same.second;
		P difa={min(ta.first,tb.second),min(ta.second,tb.first)};
		P difb={min(tb.first,ta.second),min(tb.second,ta.first)};
		ta=ta-difa,tb=tb-difb;
//		cout<<'('<<ta.first<<','<<ta.second<<')'<<' '<<'('<<tb.first<<','<<tb.second<<')'<<'\n'<<std::flush;
	}
	cout<<ans<<'\n';
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin.tie(0),cout.tie(0)->sync_with_stdio(0);
	int t;
	cin>>t;
	while (t--)
		init(),solve();
}

