#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(void) {
  int sorteios, alunos, i, segredo, tentativa, diferencaEntreTentativaSegredo,
      melhorDiferenca, alunoDaMelhorDiferenca;
  scanf("%d", &sorteios);
  while (sorteios-- > 0) {
    scanf("%d %d", &alunos, &segredo);
    scanf("%d", &tentativa);
    melhorDiferenca = segredo - tentativa;
    melhorDiferenca =
        ((melhorDiferenca) < 0 ? -(melhorDiferenca) : (melhorDiferenca));
    alunoDaMelhorDiferenca = 1;
    for (i = 2; i <= alunos; i++) {
      scanf("%d", &tentativa);
      diferencaEntreTentativaSegredo = segredo - tentativa;
      diferencaEntreTentativaSegredo = ((diferencaEntreTentativaSegredo) < 0
                                            ? -(diferencaEntreTentativaSegredo)
                                            : (diferencaEntreTentativaSegredo));
      if (diferencaEntreTentativaSegredo < melhorDiferenca) {
        melhorDiferenca = diferencaEntreTentativaSegredo;
        alunoDaMelhorDiferenca = i;
      }
    }
    printf("%d\n", alunoDaMelhorDiferenca);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecd(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
jle    1240 <main+0x120>
lea    0xea4(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xe91(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    119d <main+0x7d>
xor    %eax,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11a3 <main+0x83>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     122c <main+0x10c>
lea    0xe39(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11f5 <main+0xd5>
xor    %eax,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    11fb <main+0xdb>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1219 <main+0xf9>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    121e <main+0xfe>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b7 <main+0x97>
mov    -0x24(%rbp),%esi
lea    0xdd0(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xece(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
test   %eax,%eax
jle    1217 <main+0xf7>
lea    0xea8(%rip),%r13
lea    0xc(%rsp),%rbx
lea    0xe9f(%rip),%rbp
jmp    118e <main+0x6e>
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
test   %eax,%eax
jle    1217 <main+0xf7>
lea    0xe6b(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    $0x1,%r14d
cmpl   $0x2,0x14(%rsp)
jl     1170 <main+0x50>
mov    0x10(%rsp),%eax
sub    0xc(%rsp),%eax
mov    %eax,%r15d
neg    %r15d
cmovs  %eax,%r15d
mov    $0x1,%r12d
mov    $0x1,%r14d
xchg   %ax,%ax
add    $0x1,%r12d
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%eax
sub    0xc(%rsp),%eax
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
cmp    %r15d,%ecx
cmovl  %ecx,%r15d
cmovl  %r12d,%r14d
cmp    0x14(%rsp),%r12d
jl     11e0 <main+0xc0>
jmp    1170 <main+0x50>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [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
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %11
11: ; preds = %58, %0
%12 = load i32, i32* %2
%13 = add nsw i32 %12, -1
store i32 %13, i32* %2
%14 = icmp sgt i32 %12, 0
br i1 %14, label %15, label %61
15: ; preds = %11
%16 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %5)
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = sub nsw i32 %18, %19
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i32, i32* %8
%25 = sub nsw i32 0, %24
br label %28
26: ; preds = %15
%27 = load i32, i32* %8
br label %28
28: ; preds = %26, %23
%29 = phi i32 [ %25, %23 ], [ %27, %26 ]
store i32 %29, i32* %8
store i32 1, i32* %9
store i32 2, i32* %4
br label %30
30: ; preds = %55, %28
%31 = load i32, i32* %4
%32 = load i32, i32* %3
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %58
34: ; preds = %30
%35 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = sub nsw i32 %36, %37
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = load i32, i32* %7
%43 = sub nsw i32 0, %42
br label %46
44: ; preds = %34
%45 = load i32, i32* %7
br label %46
46: ; preds = %44, %41
%47 = phi i32 [ %43, %41 ], [ %45, %44 ]
store i32 %47, i32* %7
%48 = load i32, i32* %7
%49 = load i32, i32* %8
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = load i32, i32* %7
store i32 %52, i32* %8
%53 = load i32, i32* %4
store i32 %53, i32* %9
br label %54
54: ; preds = %51, %46
br label %55
55: ; preds = %54
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
store i32 %57, i32* %4
br label %30
58: ; preds = %30
%59 = load i32, i32* %9
%60 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %59)
br label %11
61: ; preds = %11
ret i32 0
}

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