1
3
5 3 4
 6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
 1
3
10 1 5

1
 1
-1
2
2
3
1
 1

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Dominant_Piranha {
    
    static Scanner scanner=new Scanner(System.in);
    
    static int testCases,n;
    
    static List<Integer> list=new ArrayList<>();
    
    public static void main(String[] args) {
        
        testCases=scanner.nextInt();
        
        for(int i=0;i<testCases;i++){
            
            n=scanner.nextInt();
            
            int total=0;
              
            for(int j=0;j<n;j++){
                
           list.add(j,scanner.nextInt());
                
            }
           
            //List<Integer> copyList=list;
              
            int value=-1;
            
           // System.out.println("value first: "+value);
            
           for(int j=1;j<list.size();j++){
               
               try{
            
                      value=list.get(j);
                   
                     // System.out.println("value seted: "+value);
                   
                if( list.get(j)>list.get(j+1) || list.get(j)>list.get(j-1) ){
                   
                    int u=j;
                    
             while( ( list.get(j)>list.get(j+1) || list.get(j)>list.get(j-1) )  ){
                 
                 //try{
                 
                 if( list.get(j)>list.get(j+1) && j+1<=list.size()-1 ){
                    
                     //int y=( (j+1) );
                     
                     list.remove( list.get(j+1) );
                     
                     //list.add( j,list.get(j)+1 );
                    
                     list.set(u, list.get(j)+1);
                     
                     total=list.get(u);
                     
//System.out.println("to: "+total+" size: "+list.size()+" u: "+u+" val: "+value+" list.get(j): "+list.get(j)+" list.get(j+1): "+list.get(j+1));
                     
                 }
                 
                 /*}catch(Exception e){
                     
                     
                 }*/
                 
                 else if( list.get(j)>list.get(j-1) ){
                  
                     //int y=list.get(j-1);
                     
                     //int y=( (j-1) );
                     
                     list.remove( list.get(j-1) );
                     
                    //  list.add( j,list.get(j)+1 );
                  
                   list.set(u, list.get(j)+1);
                    
                     // list.remove( list.get(j-1) );
                  
                     total=list.get(u);

// System.out.println("to1: "+total+" size: "+list.size()+" u: "+u+" val: "+value);
                     
                 }else{
                     
                    // System.out.println("i break at here: "+value);          
                     
                     break;
                     
                 }
                 
             }
              
                }
             
               }catch(Exception e){
                   
   //                System.out.println("e: "+e);
                   
               }
           
           }
           
           if(total==0){
           
               if(list.size()==n)
               if( list.get( list.size()-1 )>list.get(list.size()-2) ){
                   
                   System.out.println((list.get( list.size()-1 )+1));
                   
               }else{
               
               System.out.println("-1");
               
               }
               
               list.clear();
               
               //value=-1;
               
           }else{
                
               if(list.size()==1){
               
                   //System.out.println("value was0: "+value);
                   
                   System.out.println(list.get(0));
           
                   value=-1;
   
                   //System.out.println("val after: "+value);
                   
                   list.clear();
                   
               }
               
               else if(list.size()>=2){
                   
                   Set<Integer> set=new HashSet<>( list );
                   
                   List<Integer> copy=new ArrayList<>(set);
                   
                   if(copy.size()==1){
                       
                       System.out.println("1");
                   
                       value=-1;
                       
                       //System.out.println("value was2: "+value);
                       
                       //System.out.println("value after: "+value);
                       
                       list.clear();
                       
                   }else{
                       
                       //System.out.println("value was2: "+value);
                       
                       System.out.println(Collections.max(copy));
                   
                       value=-1;
                   
                      // System.out.println("value after: "+value);
                       
                       list.clear();
                       
                   }
                   
                   value=-1;
                   
               }
               
               //value=-1;
           
           }
           
            //System.out.println("total: "+total);
            
        }
        
    }
    
}
