#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n = 0;
  scanf("%d", &n);
  while (n--) {
    int count = 0;
    scanf("%d", &count);
    int king_pos = -1, last = 0;
    scanf("%d", &last);
    for (int i = 1; i < count; i++) {
      int curr = 0;
      scanf("%d", &curr);
      if (king_pos < 0) {
        if (last != curr - 1)
          king_pos = i + 1;
        last = curr;
      }
    }
    printf("%d\n", king_pos);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     120a <main+0xea>
movl   $0x0,-0xc(%rbp)
lea    0xe98(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0xffffffff,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe7a(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f6 <main+0xd6>
movl   $0x0,-0x1c(%rbp)
lea    0xe50(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
jge    11e3 <main+0xc3>
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     11dd <main+0xbd>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11e8 <main+0xc8>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1196 <main+0x76>
mov    -0x10(%rbp),%esi
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
jmp    1146 <main+0x26>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x10(%rsp)
lea    0xec3(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <scanf@plt>
subl   $0x1,0x10(%rsp)
jae    115f <main+0x3f>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe9a(%rip),%rbx
lea    0x8(%rsp),%r15
lea    0x14(%rsp),%r12
lea    0xe8c(%rip),%r13
jmp    1191 <main+0x71>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
subl   $0x1,0x10(%rsp)
jb     114e <main+0x2e>
movl   $0x0,0xc(%rsp)
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
movl   $0x0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    $0xffffffff,%ebp
cmpl   $0x2,0xc(%rsp)
jl     1180 <main+0x60>
mov    $0xffffffff,%ebp
mov    $0x1,%r14d
jmp    11fe <main+0xde>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x14(%rsp),%eax
lea    -0x1(%rax),%ecx
add    $0x1,%r14d
cmp    %ecx,0x8(%rsp)
cmovne %r14d,%ebp
mov    %eax,0x8(%rsp)
cmp    0xc(%rsp),%r14d
jge    1180 <main+0x60>
movl   $0x0,0x14(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
test   %ebp,%ebp
js     11e0 <main+0xc0>
add    $0x1,%r14d
cmp    0xc(%rsp),%r14d
jl     11fe <main+0xde>
jmp    1180 <main+0x60>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %38, %0
%10 = load i32, i32* %2
%11 = add nsw i32 %10, -1
store i32 %11, i32* %2
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %41
13: ; preds = %9
store i32 0, i32* %3
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 -1, i32* %4
store i32 0, i32* %5
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
store i32 1, i32* %6
br label %16
16: ; preds = %35, %13
%17 = load i32, i32* %6
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %16
store i32 0, i32* %7
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = load i32, i32* %5
%26 = load i32, i32* %7
%27 = sub nsw i32 %26, 1
%28 = icmp ne i32 %25, %27
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %32
32: ; preds = %29, %24
%33 = load i32, i32* %7
store i32 %33, i32* %5
br label %34
34: ; preds = %32, %20
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %16
38: ; preds = %16
%39 = load i32, i32* %4
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %39)
br label %9
41: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = add nsw i32 %7, -1
store i32 %8, i32* %1
%9 = icmp eq i32 %7, 0
br i1 %9, label %44, label %10
10: ; preds = %0
%11 = bitcast i32* %2 to i8*
%12 = bitcast i32* %3 to i8*
%13 = bitcast i32* %4 to i8*
br label %14
14: ; preds = %10, %19
store i32 0, i32* %2
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%17 = load i32, i32* %2
%18 = icmp sgt i32 %17, 1
br i1 %18, label %25, label %19
19: ; preds = %39, %14
%20 = phi i32 [ -1, %14 ], [ %41, %39 ]
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %1
%23 = add nsw i32 %22, -1
store i32 %23, i32* %1
%24 = icmp eq i32 %22, 0
br i1 %24, label %44, label %14
25: ; preds = %14, %39
%26 = phi i32 [ %40, %39 ], [ 1, %14 ]
%27 = phi i32 [ %41, %39 ], [ -1, %14 ]
store i32 0, i32* %4
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%29 = icmp slt i32 %27, 0
br i1 %29, label %32, label %30
30: ; preds = %25
%31 = add nuw nsw i32 %26, 1
br label %39
32: ; preds = %25
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = add nsw i32 %34, -1
%36 = icmp eq i32 %33, %35
%37 = add nuw nsw i32 %26, 1
%38 = select i1 %36, i32 %27, i32 %37
store i32 %34, i32* %3
br label %39
39: ; preds = %30, %32
%40 = phi i32 [ %31, %30 ], [ %37, %32 ]
%41 = phi i32 [ %27, %30 ], [ %38, %32 ]
%42 = load i32, i32* %2
%43 = icmp slt i32 %40, %42
br i1 %43, label %25, label %19
44: ; preds = %19, %0
ret i32 0
}