import std;
void main() {
	auto t = readln.strip.to!int;
	Attempt: foreach(tt; 0 .. t) {
		uint cm = 1;
		readln;
		auto ai = readln.split.to!(int[]);
		if(ai[0] == 1) {
			cm++;
		}
		if(ai.length >= 2) {
			foreach(i, a; ai[1 .. $]) {
				if(a == 0 && ai[i] == 0) {
					writeln("-1");
					continue Attempt;
				} else if(a == 1 && ai[i] == 1) {
					cm += 5;
				} else if(a == 1) {
					cm++;
				}
			}
		}
		writeln(cm);
	}
}