#include <bits/stdc++.h>
#define N 100005
#define ll long long
#define rint register int
#define pi pair<int,int>
using namespace std;
int n , dp[2][N] , ans=0;
int now=1 , pre=0;
char s1[N] , s2[N];
char is1[N] , is2[N];
inline void init(){
	memset( s1 , 0 , sizeof(s1) );
	memset( s2 , 0 , sizeof(s2) );
	memset( is1 , 0 , sizeof(is1) );
	memset( is2 , 0 , sizeof(is2) );
	ans = 0;
}
int main(){
	freopen( "edit.in" , "r" , stdin );
	freopen( "edit.out" , "w" , stdout );
	int T;
	scanf("%d", &T );
	while( T-- ){
		init();
		scanf("%d", &n );
		scanf("%s%s%s%s", s1+1 , s2+1 , is1+1 , is2+1 );
		bool ikun = true;
		for( rint i=2; i <= n; i++ ){
			if( s1[i]!=s1[i-1] ){
				ikun = false;
			}
		}
		if( ikun ){
			for( rint i=1; i <= n; i++ ){
				if( s2[i] == s1[i] ){
					ans ++;
				}
			}
			printf("%d\n", ans );
		}
		else{
			printf("%d\n", n );
		}
	}
}
