#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PII pair<int,int>
#define fi first
#define se second
#define VI vector<int>
#define PB emplace_back
#define PPB pop_back
#define ALL(x) x.begin(),x.end()
#define endl '\n'
using namespace std;

int n;
string a,b,c,d; // remember to batch if have time.

int main()
{
	freopen("edit.in","r",stdin),freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	
	int _;cin>>_;while(_--)
{
	cin>>n>>a>>b>>c>>d;
	VI s,t;s.PB(0),t.PB(0);
	for(int i=0;i<n;i++)
	{
		if(c[i]=='0')
		{
			if(s.back()!=i)s.PB(i);
			s.PB(i+1); 
		}
		if(d[i]=='0')
		{
			if(t.back()!=i)t.PB(i);
			t.PB(i+1); 
		}
	}
	if(c.back()=='1')s.PB(n);
	if(d.back()=='1')t.PB(n);
	int ans=0;
	for(int i=0,j=0,k=0,s0=0,s1=0,t0=0,t1=0;i<n;i++)
	{
		if(s[j]==i)
		{
			assert(!s0&&!s1);
			for(int l=s[j];l<s[j+1];l++)(a[l]=='0'?s0:s1)++;
			j++;
		}
		if(t[k]==i)
		{
			assert(!t0&&!t1);
			for(int l=t[k];l<t[k+1];l++)(b[l]=='0'?t0:t1)++;
			k++;
		}
//		cerr<<i<<" "<<s0<<" "<<s1<<" "<<t0<<" "<<t1<<endl;
		if(s0&&t0)ans++,s0--,t0--;
		else if(s1&&t1)ans++,s1--,t1--;
		else if(s1)s1--,t0--;
		else s0--,t1--;
	}
	cout<<ans<<endl;
}
	
	return 0;
}
