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

long solve (int [] a, int pos)
{
	auto n = a.length.to !(int);
	auto half = (n + 1 - pos) / 2;
	auto total = a.sum;
	if (total != half)
	{
		return long.max;
	}
	long res = 0;
	foreach (int i, ref c; a)
	{
		if (c & 1)
		{
			res += abs (i - pos);
			pos += 2;
		}
	}
	return res;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		a[] %= 2;
		auto res = long.max;
		res = min (res, solve (a, 0));
		res = min (res, solve (a, 1));
		if (res == long.max)
		{
			res = -1;
		}
		writeln (res);
	}
}
