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.io.*;
  import java.util.*;
  import java.util.List;
  
  import static java.lang.Math.*;
  
  public class ACM {
      public static void main(String args[]) throws FileNotFoundException, IOException, Exception {
  // Scanner x = new Scanner(System.in);
          StringBuilder out = new StringBuilder();
          StringTokenizer tk;
          Reader.init(System.in);
          //File initialFile = new File("road.in");
          //InputStream targetStream = new FileInputStream(initialFile);
          int t = Reader.nextInt();
          while (t-- > 0) {
              int n=Reader.nextInt();
              int [] arr = new int [n];
              int count=1;
              boolean flag=true;
              for (int i = 0; i <n ; i++) {
                  arr[i]=Reader.nextInt();
              }
  
              for (int i = 0; i < n; i++) {
  
                  if(i>=1) {
                   if(arr[i]==0 && arr[i-1]==0){
                      System.out.println(-1);
                      flag=false;
                      break;
                  }
  
                    if (arr[i] == 1 && arr[i - 1] == 1) {
                          count += 4;
  
                      }
                  }
                  if(arr[i]==1 ) {
                      count++;
                     // System.out.println("*****");
                  }
                  //System.out.println(arr[i]);
              }
              if(flag)
                  System.out.println(count);
          }
      }
  
      public static String buildTheArray(int n,int a,int b){
          int [] arr = new int[n];
          for (int i = 0; i < n; i++) {
              arr[i]=i+1;
          }
          return buildThePermutation(arr,a,b);
      }
  
      public static String buildThePermutation(int [] arr,int a,int b){
          if(a*3>arr.length)
              return "-1";
          else if(b*3>arr.length)
              return "-1";
  
              int n=arr.length-1;
              int count=0;
              for (int j = 0; j < arr.length; j+=2) {
                  int temp=arr[j+1];
                  arr[j+1]=arr[n];
                  n-=1;
                  arr[n+1]=temp;
                  count++;
                  if(count==a)
                      break;
              }
             /* if(b>=a){
                  int countt=0;
                  int nn=arr.length;
                  for (int i = arr.length-1; i >= (arr.length/2); i-=2) {
                      int temp=arr[i];
                       arr[i]=arr[i-1];
                       arr[i-1]=temp;
                       countt++;
                       if(count==b)
                           break;
                       else if(a-b==0)
                           break;
                       i-=2;
                  }
              }*/
              String s="";
          for (int i = 0; i < arr.length; i++) {
              s+=arr[i]+" ";
          }
          return s;
      }
  
      public static int sumList(List<Integer> s){
          int sum=0;
  
          for (int i = 0; i < s.size(); i++) {
              sum+=s.get(i);
          }
          return sum;
      }
  
      public static int makeItIntger(String s){
          int count=0;
  
              if(Character.getNumericValue(s.charAt(0))%2==0){
                  count++;
                  return count;
              }
              count =2;
          return count;
      }
      public static boolean checkAllOdd(String s){
          int number=Integer.parseInt(s);
          for (int i = 0; i < s.length(); i++) {
              int num=number%10;
              if(num%2==0)
                  return false;
  
              number/=10;
          }
          return true;
      }
  
      public static int solv(ArrayList<Integer>a){
          int sum=0;
          for (int i = 1; i < a.size(); i++) {
              sum+= abs(a.get(i)-a.get(i-1));
          }
          return sum;
      }
  
      static void solve() throws IOException {
          int n=Reader.nextInt();
          for (int i = 0; i < n; i++) {
              if (Reader.nextInt() != Reader.nextInt()) {
                  System.out.println("Happy Alex");
                  return;
              }
          }
          System.out.println("Poor Alex");
      }
  
      static String  xoring(String a, String b){
          String ans = "";
          for (int i = 0; i < a.length(); i++) {
              if (a.charAt(i) == b.charAt(i))
                  ans += "0";
              else
                  ans += "1";
          }
          return ans;
      }
      static String or(String a , String b){
          String ans = "";
          for (int i = 0; i <a.length() ; i++) {
              if(a.charAt(i) == b.charAt(i)){
                  ans += (a.charAt(i));
              }
              else{
                  ans += "1";
              }
          }
          return ans;
      }
      public static int  odd(int []a){
          int sum=0;
          for (int i = 0; i < a.length-2; i+=2) {
              //if(sum>Math.abs(a[i]-a[i+2]))
                 sum+= abs(a[i]-a[i+2]);
              System.out.println("ood "+sum);
  
          }
          return sum;
      }
      public static int even(int []a){
          int sum=0;
          for (int i = 1; i < a.length-2; i+=2) {
              //if(sum>Math.abs(a[i]-a[i+2]))
                 sum+= abs(a[i]-a[i+2]);
                 System.out.println("even "+ abs(a[i]-a[i+2]));
          }
          return sum;
      }
      public static Boolean areDistinct(String str, int i, int j)
      {
          boolean[] visited = new boolean[26];
          for(int k = i; k <= j; k++)
          {
              if (visited[str.charAt(k) - 'a'] == true)
                  return false;
              visited[str.charAt(k) - 'a'] = true;
          }
          return true;
      }
      public static int longestUniqueSubsttr(String str)
      {
          int n = str.length();
          int res = 0;
          for(int i = 0; i < n; i++)
              for(int j = i; j < n; j++)
                  if (areDistinct(str, i, j))
                      res = max(res, j - i + 1);
          return res;
      }
  
      public static int test1(int b,int a){
          return test2(a+b);
      }
      public static int test2 (int b){
          b+=b++;
          return b;
      }
      private static String GeneratorString(int n,int a,int b){
          char c='a';
          String str="";
          for (int i = 0; i < n; i++) {
              str += c++;
          }
          for (int i = 0; i < (n-a)+1; i++) {
              String str2=str.substring(i,a);
              HashSet<Character> HS=new HashSet<>();
              for (int j = 0; j <str2.length(); j++) {
                  HS.add(str2.charAt(i));
              }
              if(HS.size()==b) {
                  str2 = "";
                  HS.clear();
              }
              else{
                  str2.replace(str2.charAt(str2.length()-1),str2.charAt(0));
                  str.replace(str.charAt((a+i)-1),str2.charAt(str2.length()-1));
                  str2="";
                  HS.clear();
              }
          }
          return str;
      }
      public static long OrangeAndCandy(int Candy , int Orange , int minForC , int minForO){
          long count=0;
          int max = max(minForC,minForO);
          int a=Orange-minForO;
          int b=Candy-minForC;
          int min= min(a,b);
          Orange-=min;
          Candy-=min;
          count+=min;
  
          if(Candy>minForC && Orange==minForO)
              count+=Candy( Candy ,  Orange ,  minForC ,  minForO);
          else
              count+=Orange( Candy ,  Orange ,  minForC ,  minForO);
  
          return count;
      }
      public static long Orange(int Candy , int Orange , int minForC , int minForO){
          long count=Orange-minForO;;
          return count;
      }
      public static long Candy(int Candy , int Orange , int minForC , int minForO){
          long count=Candy-minForC;
          return count;
      }
      public static long gcd(long a, long b)
      {
          if (a == 0)
              return b;
          if (b == 0)
              return a;
  
          if (a == b)
              return a;
  
          if (a > b)
              return gcd(a-b, b);
          return gcd(a, b-a);
      }
      public static ArrayList<Integer> makeRound(int num){
          ArrayList <Integer> arr=new ArrayList<>();
          int count=0;
          int j=num;
          while(count>=0){
              j/=10;
              count++;
              if(j<=0)
                  break;
          }
          num=Reverse(num);
          // System.out.println(num);
          while(num>0){
              int f=num%10;
              num/=10;
              count--;
              arr.add((int) (f* pow(10,count)));
          }
          //System.out.println(arr);
          return arr;
      }
      public static boolean isRound(Integer num){
          if(num>0 && num<10)
              return true;
          else{
              String s=  num.toString();
              for (int i = s.length()-1; i > 0; i--) {
                  if(s.charAt(i) != '0') {
                      // System.out.println(s.charAt(i));
                      return false;
                  }
              }
          }
          return true;
      }
      public static int Reverse(int num){
          int reversed = 0;
          while(num != 0) {
              int digit = num % 10;
              reversed = reversed * 10 + digit;
              num /= 10;
          }
          return reversed;
      }
     /* public static int RomveZero(int num){
          String intAsString = String.valueOf(num);
          String resultString= "";
          for (char digit : intAsString.toCharArray()) {
              if(digit!='0') {
                  resultString+=digit;
              }
          }
          if (!resultString.equals("")) {
              return Integer.parseInt(resultString);
          }
          return 0;
      }*/
  
  }
  class Reader {
  
      static BufferedReader reader;
      static StringTokenizer tokenizer;
  
      static void init(InputStream input) throws UnsupportedEncodingException {
          reader = new BufferedReader(
                  new InputStreamReader(input, "UTF-8"));
          tokenizer = new StringTokenizer("");
      }
  
      static String next() throws IOException {
          while (!tokenizer.hasMoreTokens()) {
              //TODO add check for eof if necessary
              tokenizer = new StringTokenizer(
                      reader.readLine());
          }
          return tokenizer.nextToken();
      }
  
      static String nextLine() throws IOException {
          return reader.readLine();
      }
  
      static int nextInt() throws IOException {
          return Integer.parseInt(next());
      }
  
      static double nextDouble() throws IOException {
          return Double.parseDouble(next());
      }
  
      static long nextLong() throws IOException {
          return Long.parseLong(next());
      }
  }