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.math.*;
  import java.util.* ;
  import java.io.* ;
  @SuppressWarnings("unused")
  public class cf
  {
  	static final int mod = (int)1e9+7 ;
  	static final double pi = 3.1415926536 ;
  	static boolean not_prime[] = new boolean[1000001] ;
  	static void sieve() {
  		for(int i=2 ; i*i<1000001 ; i++) {
  			if(not_prime[i]==false) {
  				for(int j=2*i ; j<1000001 ; j+=i) {
  					not_prime[j]=true ;
  				}
  			}
  		}not_prime[0]=true ; not_prime[1]=true ;
  	}	
  	public static long bexp(long base , long power)
  	{
  		long res=1L ;
  		
  		base = base%mod ;
  		
  		while(power>0) {
  			if((power&1)==1) {
  				res=(res*base)%mod ;
  				power-- ;
  			}
  			else {
  				base=(base*base)%mod ;
  				power>>=1 ;
  			}
  		}
  		
  		return res ;
  	} 
  	static long modInverse(long n, long p){return power(n, p - 2, p); }
  	static long power(long x, long y, long p)
  	{
  	  
  	    // Initialize result
  	    long res = 1;
  	    x = x % p;
  	  
  	    while (y > 0) {
  	  
  	        if (y % 2 == 1)
  	            res = (res * x) % p;
  	        
  	        y = y >> 1;
  	        x = (x * x) % p;
  	    }
  	  
  	    return res;
  	}
  	static long nCrModPFermat(int n, int r, long p){if(n<r) return 0 ;if (r == 0)return 1; long[] fac = new long[n + 1];fac[0] = 1;for (int i = 1; i <= n; i++)fac[i] = fac[i - 1] * i % p;return (fac[n] * modInverse(fac[r], p) % p* modInverse(fac[n - r], p) % p) % p;}
  	static long modular_add(long a, long b){ return ((a % mod) + (b % mod)) % mod; }
  	static long modular_sub(long a, long b){ return ((a % mod) - (b % mod) + mod) % mod; }
  	static long modular_mult(long a, long b){ return ((a % mod) * (b % mod)) % mod; }
  	static long lcm(int a, int b){ return (a / gcd(a, b)) * b; }
  	static long gcd(long a, long b){if (b == 0) {return a;}return gcd(b, a % b);}
  	
  	public static void main(String[] args)throws Exception
      {
  		FastReader in = new FastReader() ;
  //	FastIO in = new FastIO(System.in) ;
  		StringBuilder op = new StringBuilder() ;
  		int T = in.nextInt() ;
  //		int T=1 ;
  		for(int tt=0 ; tt<T ; tt++)
  		{
  			int n = in.nextInt() ;
  			int a[] = in.readArray(n) ;
  			int growth=1 ;
  			if(a[0]==1)growth++ ;
  			for(int i=1 ; i<n ; i++) {
  					if(a[i]==1 && a[i-1]==1)
  						growth+=5 ;
  					else if(a[i]==1)growth++ ;
  					else if(a[i]==0 && a[i-1]==0) {
  						growth=-1 ;break ;
  					}
  			}
  			op.append(growth+"\n") ;
  		}
  		System.out.println(op.toString());
      }
  	static class pair implements Comparable<pair>
  	{
  		int first , second ;
  		pair(int first , int second){
  			this.first=first ;
  			this.second=second; 
  		}
  		@Override
  		public int compareTo(pair other) {
  			//this.first - other.first ;
  			return other.second-this.second ;
  		}
  		
  	}
  	
  	static void sort(int[] a) {
  		ArrayList<Integer> l=new ArrayList<>();
  		for (int i:a) l.add(i);
  		Collections.sort(l);
  		for (int i=0; i<a.length; i++) a[i]=l.get(i);
  	}
  	static class FastIO {
  
  		BufferedReader br= new BufferedReader(
                  new InputStreamReader(System.in));
  		
  		InputStream dis;
  		byte[] buffer = new byte[1 << 17];
  		int pointer = 0;
  
  		public FastIO(String fileName) throws Exception {
  			dis = new FileInputStream(fileName);
  		}
  
  		public FastIO(InputStream is) throws Exception {
  			dis = is;
  		}
  
  		int nextInt() throws Exception {
  			int ret = 0;
  
  			byte b;
  			do {
  				b = nextByte();
  			} while (b <= ' ');
  			boolean negative = false;
  			if (b == '-') {
  				negative = true;
  				b = nextByte();
  			}
  			while (b >= '0' && b <= '9') {
  				ret = 10 * ret + b - '0';
  				b = nextByte();
  			}
  
  			return (negative) ? -ret : ret;
  		}
  
  		long nextLong() throws Exception {
  			long ret = 0;
  
  			byte b;
  			do {
  				b = nextByte();
  			} while (b <= ' ');
  			boolean negative = false;
  			if (b == '-') {
  				negative = true;
  				b = nextByte();
  			}
  			while (b >= '0' && b <= '9') {
  				ret = 10 * ret + b - '0';
  				b = nextByte();
  			}
  
  			return (negative) ? -ret : ret;
  		}
  
  		byte nextByte() throws Exception {
  			if (pointer == buffer.length) {
  				dis.read(buffer, 0, buffer.length);
  				pointer = 0;
  			}
  			return buffer[pointer++];
  		}
  
  		String next() throws Exception {
  			StringBuffer ret = new StringBuffer();
  
  			byte b;
  			do {
  				b = nextByte();
  			} while (b <= ' ');
  			while (b > ' ') {
  				ret.appendCodePoint(b);
  				b = nextByte();
  			}
  
  			return ret.toString();
  		}
  
  		String nextLine() {
              String str = "";
              try {
                  str = br.readLine();
              }
              catch (IOException e) {
                  e.printStackTrace();
              }
              return str;
          }
  		
  		 int[] readArray(int n) throws Exception {
  				int[] a=new int[n];
  				for (int i=0; i<n; i++) a[i]=nextInt();
  				return a;
  			}
  	}
  	static class FastReader {
          BufferedReader br;
          StringTokenizer st;
   
          public FastReader()
          {
              br = new BufferedReader(
                  new InputStreamReader(System.in));
          }
   
          String next()
          {
              while (st == null || !st.hasMoreElements()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  }
                  catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
   
          int nextInt() { return Integer.parseInt(next()); }
   
          long nextLong() { return Long.parseLong(next()); }
   
          double nextDouble(){ return Double.parseDouble(next()); };
   
          String nextLine()
          {
              String str = "";
              try {
                  str = br.readLine();
              }
              catch (IOException e) {
                  e.printStackTrace();
              }
              return str;
          }
          
          int[] readArray(int n) {
  			int[] a=new int[n];
  			for (int i=0; i<n; i++) a[i]=nextInt();
  			return a;
  		}
      }
  
  }