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


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)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1192 <main+0x62>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1260 <main+0x130>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d0 <main+0xa0>
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <main+0x69>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1254 <main+0x124>
lea    0xe1c(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     1222 <main+0xf2>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf1(%rip),%rdi
call   1030 <printf@plt>
jmp    1241 <main+0x111>
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    0xdcd(%rip),%rdi
call   1030 <printf@plt>
jmp    1246 <main+0x116>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d7 <main+0xa7>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%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    0xebb(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%ebx
lea    0x0(,%rbx,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r13
mov    0x8(%rsp),%eax
cltd
idiv   %ebx
mov    %edx,0x8(%rsp)
test   %r13,%r13
je     122c <main+0xfc>
test   %ebx,%ebx
jle    11bf <main+0x8f>
lea    0xe79(%rip),%r14
mov    %r13,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     11a0 <main+0x70>
mov    0x2e12(%rip),%rbx
cmpl   $0x0,0x10(%rsp)
jle    1233 <main+0x103>
lea    0xe32(%rip),%r14
lea    0x14(%rsp),%r15
lea    0xe29(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x14(%rsp),%eax
mov    0x8(%rsp),%ecx
mov    %eax,%edx
sub    %ecx,%edx
add    0xc(%rsp),%edx
sub    %ecx,%eax
cmovl  %edx,%eax
cltq
mov    0x0(%r13,%rax,4),%esi
mov    %r12,%rdi
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    0x10(%rsp),%ebp
jl     11f0 <main+0xc0>
jmp    1233 <main+0x103>
mov    0x2dad(%rip),%rbx
mov    (%rbx),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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