#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
char s1[N], s2[N], t1[N], t2[N];
int main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int T;
	cin >> T;
	while(T--)
	{
		int n, ans = 0;
		cin >> n;
		cin >> s1 >> s2 >> t1 >> t2;
		for(int i = 0; i < n; i++)
		{
			if(s1[i] == s2[i])
			{
				ans++;
				continue;
			}
			bool b1 = 1, b2 = 1;
			for(int j = i; j < n; j++)
			{
				if(t1[j] == '0')
					b1 = 0;
				if(t2[j] == '0')
					b2 = 0;
				if(b1 && s1[j] == s2[i])
				{
					char t = s1[j];
					s1[j] = s1[i];
					s1[i] = s1[j];
					ans++;
					break;
				}
				if(b2 && s2[j] == s1[i])
				{
					char t = s2[j];
					s2[j] = s2[i];
					s2[i] = s2[j];
					ans++;
					break;
				}
				if(!b1 && !b2)
					break;	
			}
		}
		cout << ans << endl;
	}
	return 0;
}
