# include <bits/stdc++.h>
using namespace std ;
int t , n , ot ;
string s1 , s2 , t1 , t2 ;
int main ()
{
	freopen ( "edit.in" , "r" , stdin ) ;
	freopen ( "edit.out" , "w" , stdout ) ;
	ios :: sync_with_stdio ( 0 ) ;
	cin . tie ( 0 ) ;
	cout . tie ( 0 ) ;
	cin >> t ;
	while ( t -- )
	{
		cin >> n ;
		cin >> s1 >> s2 >> t1 >> t2 ;
		int ans = 0 , cnt1 = 0 , cnt2 = 0 , zr1 = 0 , zr2 = 0 ;
		int gd0 = 0 , gd1 = 0 , fx0 = 0 , fx1 = 0 , lst = -1 ;
		for ( int i = 0 ; i < n ; i ++ )
		{
			if ( t1 [ i ] == t2 [ i ] && t1 [ i ] == '0' )
			{
				if ( s1 [ i ] == s2 [ i ] )	
					ans ++ ;
				ans += min ( cnt1 , cnt2 ) + min ( zr1 , zr2 ) ;
				int cp1 = cnt2 , cp2 = zr2 ;
				cnt2 = max ( 0 , cnt2 - cnt1 ) , zr2 = max ( 0 , zr2 - zr1 ) ;
				cnt1 = max ( 0 , cnt1 - cp1 ) , zr1 = max ( 0 , zr1 - cp2 ) ;
				ans += min ( gd1 , cnt2 ) + min ( gd0 , zr2 ) + min ( fx1 , cnt1 ) + min ( fx0 , zr1 ) ;
				cnt1 = cnt2 = zr1 = zr2 = 0 ;
				gd0 = gd1 = fx0 = fx1 = 0 ;
				lst = -1 ;
				continue ;
			}
			if ( t1 [ i ] == '0' )
			{
				if ( s2 [ i ] == '1' )
					cnt2 ++ ;
				else
					zr2 ++ ;
				if ( lst == -1 || lst == 0 )
				{
					if ( s1 [ i ] == '1' )
						gd1 ++ ;
					else
						gd0 ++ ;
					lst = 0 ;
				}
				else
				{
					ans += min ( cnt1 , fx1 ) + min ( zr1 , fx0 ) ;
					cnt1 = max ( 0 , cnt1 - fx1 ) , zr1 = max ( 0 , zr1 - fx0 ) ;
					fx1 = fx0 = 0 ;
					if ( s1 [ i ] == '1' )
						gd1 ++ ;
					else
						gd0 ++ ;
					lst = 0 ;
				}
				ans += min ( cnt1 , cnt2 ) + min ( zr1 , zr2 ) ;
				cnt2 = max ( 0 , cnt2 - cnt1 ) , zr2 = max ( 0 , zr2 - zr1 ) ;
				cnt1 = zr1 = 0 ;
				continue ;
			}
			if ( t2 [ i ] == '0' )
			{
				if ( s1 [ i ] == '1' )
					cnt1 ++ ;
				else
					zr1 ++ ;
				if ( lst == -1 || lst == 1 )
				{
					if ( s2 [ i ] == '1' )
						fx1 ++ ;
					else
						fx0 ++ ;
					lst = 1 ;
				}
				else
				{
					ans += min ( cnt2 , gd1 ) + min ( zr2 , gd0 ) ;
					cnt2 = max ( 0 , cnt2 - gd1 ) , zr2 = max ( 0 , zr2 - gd0 ) ;
					gd1 = gd0 = 0 ;
					if ( s2 [ i ] == '1' )
						fx1 ++ ;
					else
						fx0 ++ ;
					lst = 1 ;
				}
				ans += min ( cnt1 , cnt2 ) + min ( zr1 , zr2 ) ;
				cnt1 = max ( 0 , cnt1 - cnt2 ) , zr1 = max ( 0 , zr1 - zr2 ) ;
				cnt2 = zr2 = 0 ;
				continue ;
			}
			if ( s2 [ i ] == '1' )
				cnt2 ++ ;
			else
				zr2 ++ ;
			if ( s1 [ i ] == '1' )
				cnt1 ++ ;
			else
				zr1 ++ ;
		}
		ans += min ( cnt1 + gd1 , cnt2 + fx1 ) + min ( zr1 + gd0 , zr2 + fx0 ) ;
		cout << ans << '\n' ;
	}
	return 0 ;
}
