#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 *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int n;
  int k;
  int q;
  scanf("%d %d %d", &n, &k, &q);
  int *a = malloc(sizeof(int) * n);
  for (int a_i = 0; a_i < n; a_i++) {
    scanf("%d", &a[a_i]);
  }
  for (int a0 = 0; a0 < q; a0++) {
    int m;
    scanf("%d", &m);
    if (m >= k) {
      printf("%d\n", a[m - k]);
    } else if (m < k) {
      printf("%d\n", a[n + m - k]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1050 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11aa <main+0x7a>
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1173 <main+0x43>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    123f <main+0x10f>
lea    0xe42(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     11fc <main+0xcc>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
jmp    122c <main+0xfc>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1227 <main+0xf7>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    -0x24(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xde7(%rip),%rdi
call   1030 <printf@plt>
jmp    122c <main+0xfc>
jmp    1231 <main+0x101>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b1 <main+0x81>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebc(%rip),%rdi
mov    %rsp,%rsi
lea    0xc(%rsp),%rdx
lea    0x4(%rsp),%rcx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    (%rsp),%ebx
lea    0x0(,%rbx,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r13
test   %ebx,%ebx
jle    119e <main+0x6e>
lea    0xe91(%rip),%r14
mov    %r13,%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq (%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1180 <main+0x50>
cmpl   $0x0,0x4(%rsp)
jle    11f9 <main+0xc9>
lea    0xe5a(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xe51(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
mov    %eax,%edx
sub    %ecx,%edx
add    (%rsp),%edx
sub    %ecx,%eax
cmovl  %edx,%eax
cltq
mov    0x0(%r13,%rax,4),%esi
mov    %r12,%rdi
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    0x4(%rsp),%ebx
jl     11c0 <main+0x90>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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