#include <iostream>
#include <cstdio>
using namespace std;
const int maxn=10e5+10;
int t, n;
string s1, s2, t1, t2;
int ans;
int fa[maxn<<1];
void solve()
{
	cin>>n;
	cin>>s1>>s2>>t1>>t2;
	ans=0;
	for(int i=0;i<n-1;i++)
	{
		int ok = 0;
		if(t1[i]=='1'&&t1[i+1]=='1')
		{
			if(s1[i]!=s1[i+1]&&(s2[i]!=s2[i+1]||(s2[i]==s2[i+1]&&s1[i+1]==s2[i]))) swap(s1[i], s1[i+1]), ok=1;
		}
		if(t2[i]=='1'&&t2[i+1]=='1')
		{
			if(s2[i]!=s2[i+1]&&((s1[i]!=s1[i+1]&&!ok)||(s1[i]==s1[i+1]&&s1[i]==s2[i+1]))) swap(s2[i], s2[i+1]); 
		}
	}
	for(int i=0;i<n;i++)
	{
		ans+=(s1[i]==s2[i]);
	}
	cout<<ans<<endl;
}
int main()
{
	ios::sync_with_stdio(false);
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w",stdout);

	cin>>t;
	while(t--)
		solve();
		
	fclose(stdin);
	fclose(stdout);
	return 0;
}
