description: Petya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given n days from Petya's live and you have to determine what happened with his flower in the end.
  
  The flower grows as follows: 
  
    * If the flower isn't watered for two days in a row, it dies. 
    * If the flower is watered in the i-th day, it grows by 1 centimeter. 
    * If the flower is watered in the i-th and in the (i-1)-th day (i > 1), then it grows by 5 centimeters instead of 1. 
    * If the flower is not watered in the i-th day, it does not grow. 
  
  
  
  At the beginning of the 1-st day the flower is 1 centimeter tall. What is its height after n days?
  
  Input
  
  Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 100). Description of the test cases follows.
  
  The first line of each test case contains the only integer n (1 ≤ n ≤ 100).
  
  The second line of each test case contains n integers a_1, a_2, ..., a_n (a_i = 0 or a_i = 1). If a_i = 1, the flower is watered in the i-th day, otherwise it is not watered.
  
  Output
  
  For each test case print a single integer k — the flower's height after n days, or -1, if the flower dies.
  
  Example
  
  Input
  
  
  4
  3
  1 0 1
  3
  0 1 1
  4
  1 0 0 1
  1
  0
  
  
  Output
  
  
  3
  7
  -1
  1
solution: import java.util.*;
  import java.util.Map.Entry;
  import java.io.*;
  
  public class Main {
  	static long[]fac=new long[200100];
  	static long[] two= new long[200100] ;
  	static long mod=(long)1e9+7;
  	static int n,k;
  	static int x=0;
  	static int[][]perm;
  	static int[]pe,aa,a,b,c;
  	static int[]prime=new int[(int)1e5+100];
  	static TreeSet<Long>p=new TreeSet<Long>();
  	static long[][]memo;
  	public static void main(String[] args) throws IOException{
  		int t=sc.nextInt();
  		while(t-->0) {
  			int n=sc.nextInt();
  			int[]a=sc.nextArrint(n);
  			boolean f=false;
  			int s=1;
  			for (int i = 0; i < a.length; i++) {
  				if(i>=1&&a[i]==a[i-1]&&a[i]==0) {
  					f=true;
  					break;
  				}else if(a[i]==1) {
  					if(i>=1&&a[i-1]==1)s+=5;
  					else s+=1;
  				}
  			}
  			pw.println(f?-1:s);
  		}
  		pw.close();
  	}	
  	
  	
  	
  	public static int divNum(int n) {
  		int total = 1;
  		
  		while(n>1) {
  			int p=prime[n];
  			int count =1;
  			while(n%p==0) {
  				n/=p;
  				count++;
  			}
  			total*=count;
  		}
  	    
  	    return total;
  	}
  	
  	public static void sieve() {
  		for (int i = 2; i < prime.length; i++) {
  			if(prime[i]==0) {
  				p.add((long)i);
  				for (int j = i; j < prime.length; j+=i) {
  					if(prime[j]==0)prime[j]=i;
  				}
  			}
  		}
  	}
  	
  	public static long[] Extended(long p, long q) {
  	      if (q == 0)
  	         return new long[] { p, 1, 0 };
  
  	      long[] vals = Extended(q, p % q);
  	      long d = vals[0];
  	      long a = vals[2];
  	      long b = vals[1] - (p / q) * vals[2];
  	      return new long[] { d, a, b };
  	}
  
  	public static int LIS(int[] a) {
  
  		int n = a.length;
  		int[] ser = new int[n];
  		Arrays.fill(ser, Integer.MAX_VALUE);
  		int cur = -1;
  		for (int i = 0; i < n; i++) {
  			int low = 0;
  			int high = n - 1;
  			int mid = (low + high) / 2;
  			while (low <= high) {
  				if (ser[mid] < a[i]) {
  					low = mid + 1;
  				} else {
  					high = mid - 1;
  				}
  				mid = (low + high) / 2;
  			}
  			cur = Math.max(cur, high + 1);
  			ser[high + 1] = Math.min(ser[high + 1], a[i]);
  		}
  
  		return cur + 1;
  	}
  	
  	
  	
  	public static void permutation(int idx,int v) {
  		if(v==(1<<n)-1) {
  			perm[x++]=pe.clone();
  			return ;
  		}
  		for (int i = 0; i < n; i++) {
  			if((v&1<<i)==0) {
  				pe[idx]=aa[i];
  				permutation(idx+1, v|1<<i);
  			}
  		}
  		return ;
  	}
  		
  	public static void sort(int[]a) {
  		mergesort(a, 0, a.length-1);
  	}
  	
  	public static void sortIdx(long[]a,long[]idx) {
  		mergesortidx(a, idx, 0, a.length-1);
  	}
  	
  	public static long C(int a,int b) {
  		long x=fac[a];
  		long y=fac[a-b]*fac[b];
  		return x*pow(y,mod-2)%mod;
  	}
  	
  	public static long pow(long a,long b) {
  		long ans=1;a%=mod;
  		for(long i=b;i>0;i/=2) {
  			if((i&1)!=0)
  				ans=ans*a%mod;
  			a=a*a%mod;
  		 }    
  		    
  		 return ans;
  	}
  	
  	public static void pre(){
  		fac[0]=1;
  		fac[1]=1;
  		fac[2]=1;
  		for (int i = 3; i < fac.length; i++) {
  			fac[i]=((fac[i-1]*2*i)/2)%mod;
  		}
  	}
  	
  	public static long eval(String s) {
  		long p=1;
  		long res=0;
  		for (int i = 0; i < s.length(); i++) {
  			res+=p*(s.charAt(s.length()-1-i)=='1'?1:0);
  			p*=2;
  		}
  		return res;
  	}
  	
  	public static String binary(long x) {
  		String s="";
  		while(x!=0) {
  			s=(x%2)+s;
  			x/=2;
  		}
  		return s;
  	}
  	
  	public static boolean allSame(String s) {
  		char x=s.charAt(0);
  		for (int i = 0; i < s.length(); i++) {
  			if(s.charAt(i)!=x)return false;
  		}
  		return true;
  	}
  	
  	public static boolean isPalindrom(String s) {
  		int l=0;
  		int r=s.length()-1;
  		while(l<r) {
  			if(s.charAt(r--)!=s.charAt(l++))return false;
  		}
  		return true;
  	}
  	 
  	
  	public static boolean isSubString(String s,String t) {
  		int ls=s.length();
  		int lt=t.length();
  		boolean res=false;
  		for (int i = 0; i <=lt-ls; i++) {
  			if(t.substring(i, i+ls).equals(s)) {
  				res=true;
  				break;
  			}
  		}
  		return res;
  	}
  	
  	public static boolean isSorted(long[]a) {
  		for (int i = 0; i < a.length-1; i++) {
  			if(a[i]>a[i+1])return false;
  		}
  		return true;
  	}
  	
  	
  	public static long evaln(String x,int n) {
  		long res=0;
  		for (int i = 0; i < x.length(); i++) {
  			res+=Long.parseLong(x.charAt(x.length()-1-i)+"")*Math.pow(n, i);
  		}
  		return res;
  	}
  	static void mergesort(int[] arr,int b,int e) {
  		if(b<e) {
  			int m=b+(e-b)/2;
  			mergesort(arr,b,m);
  			mergesort(arr,m+1,e);
  			merge(arr,b,m,e);
  		}
  		return;
  		
  	}
  	static void merge(int[] arr,int b,int m,int e) {
  		int len1=m-b+1,len2=e-m;
  		int[] l=new int[len1];
  		int[] r=new int[len2];
  		for(int i=0;i<len1;i++)l[i]=arr[b+i];
  		for(int i=0;i<len2;i++)r[i]=arr[m+1+i];
  		int i=0,j=0,k=b;
  		while(i<len1 && j<len2) {
  			if(l[i]<r[j])arr[k++]=l[i++];
  			else arr[k++]=r[j++];
  		}
  		while(i<len1)arr[k++]=l[i++];
  		while(j<len2)arr[k++]=r[j++];
  		return;
  	}
  	
  	static void mergesortidx(long[] arr,long[]idx,int b,int e) {
  		if(b<e) {
  			int m=b+(e-b)/2;
  			mergesortidx(arr,idx,b,m);
  			mergesortidx(arr,idx,m+1,e);
  			mergeidx(arr,idx,b,m,e);
  		}
  		return;
  		
  	}
  	static void mergeidx(long[] arr,long[]idx,int b,int m,int e) {
  		int len1=m-b+1,len2=e-m;
  		long[] l=new long[len1];
  		long[] lidx=new long[len1];
  		long[] r=new long[len2];
  		long[] ridx=new long[len2];
  		for(int i=0;i<len1;i++) {
  			l[i]=arr[b+i];
  			lidx[i]=idx[b+i];
  		}
  		for(int i=0;i<len2;i++) {
  			r[i]=arr[m+1+i];
  			ridx[i]=idx[m+1+i];
  		}
  		int i=0,j=0,k=b;
  		while(i<len1 && j<len2) {
  			if(l[i]<=r[j]) {
  				arr[k++]=l[i++];
  				idx[k-1]=lidx[i-1];
  			}
  			else {
  				arr[k++]=r[j++];
  				idx[k-1]=ridx[j-1];
  			}
  		}
  		while(i<len1) {
  			idx[k]=lidx[i];
  			arr[k++]=l[i++];
  		}
  		while(j<len2) {
  			idx[k]=ridx[j];
  			arr[k++]=r[j++];
  		}
  		return;
  	}
  	
  	
  	
  	static long mergen(int[] arr,int b,int m,int e) {
  		int len1=m-b+1,len2=e-m;
  		int[] l=new int[len1];
  		int[] r=new int[len2];
  		for(int i=0;i<len1;i++)l[i]=arr[b+i];
  		for(int i=0;i<len2;i++)r[i]=arr[m+1+i];
  		int i=0,j=0,k=b;
  		long c=0;
  		while(i<len1 && j<len2) {
  			if(l[i]<r[j])arr[k++]=l[i++];
  			else {
  				arr[k++]=r[j++];
  				c=c+(long)(len1-i);
  			}
  		}
  		while(i<len1)arr[k++]=l[i++];
  		while(j<len2)arr[k++]=r[j++];
  		return c;
  	}
  	static long mergesortn(int[] arr,int b,int e) {
  		long c=0;
  		if(b<e) {
  			int m=b+(e-b)/2;
  			c=c+(long)mergesortn(arr,b,m);
  			c=c+(long)mergesortn(arr,m+1,e);
  			c=c+(long)mergen(arr,b,m,e);
  		}
  		return c;
  		
  	}
  	
  	public static long gcd(long a, long b)
      {
        if (b == 0)
          return a;
        return gcd(b, a % b);
      }
       
  	public static long sumd(long x) {
  		long sum=0;
  		while(x!=0) {
  			sum+=x%10;
  			x=x/10;
  		}
  		return sum;
  				
  	}
  	
  	public  static ArrayList<Integer> findDivisors(int n){
  	        ArrayList<Integer>res=new ArrayList<Integer>();
  	        for (int i=1; i<=Math.sqrt(n); i++)
  	        {
  	            if (n%i==0)
  	            {
  	                // If divisors are equal, print only one
  	                if (n/i == i)
  	                	res.add(i);
  	                else {
  	                	res.add(i);
  	                	res.add(n/i);
  	                }	
  	            }
  	        }
  	        return res;
  	    }
  
  	
  	public static void sort2darray(Integer[][]a){
  		Arrays.sort(a,Comparator.<Integer[]>comparingInt(x -> x[0]).thenComparingInt(x -> x[1]));
   
  	}
  		
  	static class Scanner {
  		StringTokenizer st;
  		BufferedReader br;
  		public Scanner(InputStream s) {
  			br = new BufferedReader(new InputStreamReader(s));
  		}
  		public Scanner(String file) throws FileNotFoundException {
  			br = new BufferedReader(new FileReader(file));
  		}
   
  		public String next() throws IOException {
  			while (st == null || !st.hasMoreTokens())
  				st = new StringTokenizer(br.readLine());
  			return st.nextToken();
  		}
  		
  		public int nextInt() throws IOException {
  			return Integer.parseInt(next());
  		}
  		public long nextLong() throws IOException {
  			return Long.parseLong(next());
  		}
  		public String nextLine() throws IOException {
  			return br.readLine();
  		}
  		public double nextDouble() throws IOException {
  			return Double.parseDouble(next());
  		}
  		public boolean ready() throws IOException {
  			return br.ready();
  		}
  		public int[] nextArrint(int size) throws IOException {
  			int[] a=new int[size];
  			for (int i = 0; i < a.length; i++) {
  				a[i]=sc.nextInt();
  			}
  			return a;
  		}
  		public long[] nextArrlong(int size) throws IOException {
  			long[] a=new long[size];
  			for (int i = 0; i < a.length; i++) {
  				a[i]=sc.nextLong();
  			}
  			return a;
  		}
  		public int[][] next2dArrint(int rows,int columns) throws IOException{
  			int[][]a=new int[rows][columns];
  			for (int i = 0; i < rows; i++) {
  				for (int j = 0; j < columns; j++) {
  					a[i][j]=sc.nextInt();
  				}
  			}
  			return a;
  		}
  		public long[][] next2dArrlong(int rows,int columns) throws IOException{
  			long[][]a=new long[rows][columns];
  			for (int i = 0; i < rows; i++) {
  				for (int j = 0; j < columns; j++) {
  					a[i][j]=sc.nextLong();
  				}
  			}
  			return a;
  		}
  	}
  	
  	static Scanner sc=new Scanner(System.in);
  	static PrintWriter pw=new PrintWriter(System.out);
  }