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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;


public class A {
	static class FastReader 

	{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() throws Exception
		{ 
			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(); 
		} 
		char nextChar() {
			String str = "";
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str.charAt(0);
			
		}
		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] = Integer.parseInt(next());
			}
			return a;
		}
		void debug(Object...args)
	    {
	        System.out.println(Arrays.deepToString(args));
	    }
	} 
	public static void main(String[] args) throws Exception {
		FastReader scan =new FastReader();
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		int t = scan.nextInt();
		outer:while(t-- > 0) {
			
			int n = scan.nextInt();
			int[] a = scan.readArray(n);
			for(int i = 1; i < n; i++) {
				if(a[i - 1] < a[i]) {
					out.println(a[i - 1]);
					continue outer;
				}
			}
			for(int i = 0; i < n - 1; i++) {
				if(a[i+1] < a[i]) {
					out.println(a[i - 1]);
					continue outer;
				}
			}
			out.println(-1);
		}
		out.flush();
	}

}