#include<bits/stdc++.h>
using namespace std;
int t;
int n;
string s1,s2,t1,t2;
int p(string x,string y)
{
	int ans;
	if(t1==t2)
	{
		int c1,c2,c3,c4;
		c1=c2=c3=c4=0;
		for(int i=0;i<n;i++)
		{
			if(t1[i]=='0')
			{
				ans+=min(c1,c3)+min(c2,c4);
				ans+=(s1[i]==s2[i])? 1:-1;
				c1=c2=c3=c4=0;
			}
			else
			{
				c1+=(s1[i]=='0')? 1:0;
				 c2+=(s1[i]=='1')? 1:0;
				c3+=(s2[i]=='0')? 1:0;
				 c4+=(s2[i]=='1')? 1:0; 	
			}
		}
		if(t1[t1.length()-1]=='1') ans+=min(c1,c3)+min(c2,c4);
		return ans;
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>t;
	//priority_queue<int,vector<int>,greater<int> > a; 
	while(t--)
	{
		int cnt,tmp,c1,c2;
		c1=0;c2=0;
		tmp=cnt=0;
		cin>>n;
		cin>>s1;
		cin>>s2;
		cin>>t1;
		cin>>t2;
		for(int i=0;i<s1.length();i++)
		{
			if(s1[i]=='1') c1++;
			else c2++; 
		}
		if(c1==s1.length() || c2==s1.length())
		{
			int ans=max(c1,c2);
			for(int i=0;i<n;i++)
			if(s1[i]!=s2[i]) ans--;
			cout<<ans<<'\n';
			continue;
		}
		//cout<<t1<<" "<<t2<<endl;
		if(t1==t2)
		{
			int ans;
			ans=p(s1,s2);
			cout<<ans<<'\n';
			continue;
		}
		while(cnt<=n)
		{
			while(pd_s1[cnt]=='1' && pd_s2[cnt]=='1')
			{
				while(pd_s1[cnt]=='1') cnt++;
				if(pd_s2[cnt]!='1')
				{
					break;
				}
				while(pd_s2[cnt]=='1') cnt++;
				//cnt--;
			}
			cout<<tmp<<" "<<cnt<<endl;
			if(cnt-tmp==1) ans+=(s1[tmp]==s2[tmp])? 1:0;
			else ans+=p(s1.substr(tmp,cnt),s2.substr(tmp,cnt));
			tmp=cnt;
			cnt++;
			ans+=p(s1.substr(tmp,cnt),s2.substr(tmp,cnt));
		}
		//panduan 
		//cout<<s1.substr(0,1);
	 } 
}
