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

long solve (int [] a, int n)
{
	if (a[1..$ - 1].all !(q{a == 0}))
	{
		return 0;
	}
	if (a[1..$ - 1].all !(q{a <= 1}))
	{
		return -1;
	}
	if (n == 3 && a[1] % 2 == 1)
	{
		return -1;
	}
	long res = 0;
	foreach (i; 1..n - 1)
	{
		res += a[i] / 2 + (a[i] & 1);
	}
	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;
		writeln (solve (a, n));
	}
}
