import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.strip.map !(q{a - '0'}).array;
		auto b = readln.strip.map !(q{a - '0'}).array;

		int mex (int lo, int hi)
		{
			bool [3] c;
			foreach (i; lo..hi)
			{
				c[a[i]] = true;
				c[b[i]] = true;
			}
			int res = 0;
			while (c[res])
			{
				res += 1;
			}
			return res;
		}

		auto f = new int [n + 1];
		f[0] = 0;
		f[1] = mex (0, 1);
		foreach (i; 2..n + 1)
		{
			foreach (j; 1..3)
			{
				f[i] = max (f[i], mex (i - j, i) + f[i - j]);
			}
		}
		writeln (f[n]);
	}
}
