#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int t,n;
int a[maxn],b[maxn];
int sm1[maxn],sm2[maxn];
char t1[maxn],t2[maxn];
string s1,s2;
vector<pair<int,int> > G1,G2;
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>t;
	while (t--){
		cin>>n;
		cin>>s1>>s2;
		for (int i=0;i<n;i++)a[i+1]=s1[i]-'0';		
		for (int i=0;i<n;i++)b[i+1]=s2[i]-'0';
		for (int i=1;i<=n;i++)sm1[i]=sm1[i-1]+a[i];
		for (int i=1;i<=n;i++)sm2[i]=sm2[i-1]+b[i];
		for (int i=1;i<=n;i++)cin>>t1[i];
		t1[n+1]='0';
		t2[n+1]='0';
		for (int i=1;i<=n;i++)cin>>t2[i];
		int lst=0;
		for (int i=1;i<=n+1;i++){
			if (t1[i]=='0'){
				if (i-1>=lst+1)G1.push_back(make_pair(lst+1,i-1));
				G1.push_back(make_pair(i,i));
				lst=i;
			}
		}
		lst=0;
		for (int i=1;i<=n+1;i++){
			if (t2[i]=='0'){
				if (i-1>=lst+1)G2.push_back(make_pair(lst+1,i-1));
				G2.push_back(make_pair(i,i));
				lst=i;
			}
		}
		int x=0,y=0;
		int xx=0,yy=0;
		int c1=0,c2=0;
		int ans=0;
//		for (auto i:G1){
//			cout<<i.first<<' '<<i.second<<'\n';
//		} 
//		cout<<'\n';
//		for (auto i:G2){
//			cout<<i.first<<' '<<i.second<<'\n';
//		} 
		for (int i=1;i<=n;i++){
			if (!x&&!y){
				int l=G1[c1].first,r=G1[c1].second;
				int len=r-l+1;
				y=(sm1[r]-sm1[l-1]);
				x=len-y;
				c1++;
			}
			if (!xx&&!yy){
				int l=G2[c2].first,r=G2[c2].second;
				int len=r-l+1;
				yy=(sm2[r]-sm2[l-1]);
				xx=len-yy;
				c2++;
			}
//			cout<<i<<' '<<x<<' '<<y<<' '<<xx<<' '<<yy<<'\n';
			if (x&&xx){
				x--,xx--;
				ans++;
				continue;
			}
			if (y&&yy){
				y--;
				yy--;
				ans++;
				continue;
			}
			if (x)x--;
			if (y)y--;
			if (xx)xx--;
			if (yy)yy--;
		}
		G1.clear(),G2.clear();
		cout<<ans<<'\n';
	}
	return 0;
}
/*
1
9
101111111
100111000
110111011
011111111

*/
