#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N=1e5+5;
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	
	int T;cin>>T;
	while(T--)
	{
		int n;cin>>n;
		string s1,s2;cin>>s1>>s2;
		string t1,t2;cin>>t1>>t2;
		vector<pair<int,int>> V;
		for(int i=0;i<n;i++){
			if(t1[i]=='0') V.pb({1,i});
			if(t2[i]=='0') V.pb({2,i});
		}
		V.pb({1,n+1});V.pb({2,n+1});
		int SZ=V.size();
		int ans=0;
		int cnt0=0,cnt1=0,cnt2=0,cnt3=0;
		int pos=0,i=0,j=0;
		bool flag;
		while(pos<SZ){
			flag=false;
			if(V[pos].fi==1){
				if(i>=n) {pos++;continue;}
				while(i<n&&t1[i]!='0') {
					if(s1[i]=='0') cnt0++;
					else cnt1++;
					i++;
				}
				if(pos+1<SZ&&V[pos].se==V[pos+1].se) flag=true;
				else {
					ans+=min(cnt0,cnt2);
					ans+=min(cnt1,cnt3);
					cnt0-=cnt2,cnt1-=cnt3;
					if(cnt0<0) cnt1+=cnt0,cnt0=0;
					if(cnt1<0) cnt0+=cnt1,cnt1=0;
					cnt2=cnt3=0;
					if(i<n&&s1[i]=='0') cnt0++;
					else cnt1++;
				}
				i++;
				pos++;
			}
			if(pos<SZ&&V[pos].fi==2){
				if(j>=n) {pos++;continue;}
				while(j<n&&t2[j]!='0') {
					if(s2[j]=='0') cnt2++;
					else cnt3++;
					j++;
				}
				ans+=min(cnt0,cnt2);
				ans+=min(cnt1,cnt3);
				cnt2-=cnt0,cnt3-=cnt1;
				if(cnt2<0) cnt3+=cnt2,cnt2=0;
				if(cnt3<0) cnt2+=cnt3,cnt3=0;
				if(flag){
					cnt0=cnt1=cnt2=cnt3=0;
				}
				else {
					cnt0=cnt1=0;
					if(j<n&&s2[j]=='0') cnt2++;
					else cnt3++;
				}
				j++;
				pos++;
			}
		}
		for(int i=0;i<n;i++) if(t1[i]=='0'&&t1[i]==t2[i]&&s1[i]==s2[i]) ans++;
		cout<<ans<<endl;
	}
	return 0;
}
/*
1
10
0110111100
1111111100
1110000100
0110111011
*/
