#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, k, q;
  scanf("%i %i %i", &n, &k, &q);
  k %= n;
  int arr[n], i;
  for (i = 0; i < n; i++) {
    scanf("%i", arr + i);
  }
  int m;
  for (i = 0; i < q; i++) {
    scanf("%i", &m);
    printf("%i\n", arr[m - k >= 0 ? m - k : m - k + n]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
xor    %eax,%eax
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1040 <scanf@plt>
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ba <main+0x9a>
mov    -0x30(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1183 <main+0x63>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    122f <main+0x10f>
lea    0xe32(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x28(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x0,%eax
jl     11fc <main+0xdc>
mov    -0x28(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    1208 <main+0xe8>
mov    -0x28(%rbp),%eax
sub    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xded(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c1 <main+0xa1>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xec8(%rip),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rsp,-0x40(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x30(%rbp)
mov    %rsp,%r13
lea    0xf(,%rcx,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    11ae <main+0x8e>
lea    0xe89(%rip),%r14
mov    %r13,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1190 <main+0x70>
cmpl   $0x0,-0x34(%rbp)
jle    1207 <main+0xe7>
lea    0xe4b(%rip),%r14
lea    -0x38(%rbp),%r15
lea    0xe43(%rip),%rbx
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    -0x38(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,%ecx
sar    $0x1f,%ecx
and    -0x2c(%rbp),%ecx
add    %eax,%ecx
movslq %ecx,%rax
mov    0x0(%r13,%rax,4),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0x1,%r12d
cmp    -0x34(%rbp),%r12d
jl     11d0 <main+0xb0>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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