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

int solve (int n, bool [] a, bool [] b)
{
	auto aOnes = a.sum.to !(int);
	auto bOnes = b.sum.to !(int);
	auto same = n.iota.count !(i => a[i] == b[i]).to !(int);
	auto diff = n - same;
	int res = int.max;
	if (aOnes == bOnes)
	{
		res = min (res, diff);
	}
	if (aOnes + bOnes == n + 1)
	{
		res = min (res, same);
	}
	if (res == int.max)
	{
		res = -1;
	}
	return res;
}

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 == '1'}).array;
		auto b = readln.strip.map !(q{a == '1'}).array;
		writeln (solve (n, a, b));
	}
}
