#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*/ bubble_sort(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int N, T, M, C, D, i, j, cnt;
  int c[101];
  scanf("%d", &D);
  for (j = 0; j < D; j++) {
    scanf("%d %d", &N, &T);
    scanf("%d", &M);
    cnt = 0;
    for (i = 0; i < M; i++) {
      scanf("%d", &C);
      c[cnt] = (C + T) % N;
      cnt++;
    }
    bubble_sort(c, cnt);
    for (i = 0; i < cnt; i++) {
      if (i != 0) {
        printf(" ");
      }
      printf("%d", c[i]);
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1264 <main+0x134>
lea    0xe92(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xe7f(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e7 <main+0xb7>
lea    0xe53(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
movslq -0x24(%rbp),%rax
mov    %edx,-0x1c0(%rbp,%rax,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119d <main+0x6d>
lea    -0x1c0(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <bubble_sort@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1248 <main+0x118>
cmpl   $0x0,-0x1c(%rbp)
je     1221 <main+0xf1>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x1c(%rbp),%rax
mov    -0x1c0(%rbp,%rax,4),%esi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11fd <main+0xcd>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115b <main+0x2b>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1b8,%rsp
lea    0xeab(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1286 <main+0x146>
lea    0xe8d(%rip),%r12
lea    0x14(%rsp),%r14
xor    %ebx,%ebx
jmp    11a7 <main+0x67>
nop
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1060 <bubble_sort@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x10(%rsp),%ebx
add    $0x1,%ebx
cmp    0x8(%rsp),%ebx
jge    1286 <main+0x146>
lea    0xe52(%rip),%rdi
lea    0x1c(%rsp),%rsi
lea    0x18(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r12,%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
mov    %ebx,0x10(%rsp)
jle    1180 <main+0x40>
mov    $0x1,%eax
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%r13d
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x18(%rsp),%eax
add    0x14(%rsp),%eax
cltd
idivl  0x1c(%rsp)
mov    %edx,0x20(%rsp,%r15,4)
add    $0x1,%r15
lea    0x1(%r13),%eax
cmp    %r15d,0xc(%rsp)
jg     11f0 <main+0xb0>
lea    0x20(%rsp),%rdi
mov    %r15d,%esi
call   1060 <bubble_sort@plt>
test   %r15d,%r15d
je     118c <main+0x4c>
mov    0x20(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r15d
je     118c <main+0x4c>
mov    %r13d,%ebp
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0x20(%rsp,%rbx,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1260 <main+0x120>
jmp    118c <main+0x4c>
xor    %eax,%eax
add    $0x1b8,%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 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\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
%10 = alloca [101 x i32]
store i32 0, i32* %1
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
store i32 0, i32* %8
br label %12
12: ; preds = %62, %0
%13 = load i32, i32* %8
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %65
16: ; preds = %12
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%18 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
store i32 0, i32* %9
store i32 0, i32* %7
br label %19
19: ; preds = %35, %16
%20 = load i32, i32* %7
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %38
23: ; preds = %19
%24 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%25 = load i32, i32* %5
%26 = load i32, i32* %3
%27 = add nsw i32 %25, %26
%28 = load i32, i32* %2
%29 = srem i32 %27, %28
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [101 x i32], [101 x i32]* %10, i64 0, i64 %31
store i32 %29, i32* %32
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %35
35: ; preds = %23
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %19
38: ; preds = %19
%39 = getelementptr inbounds [101 x i32], [101 x i32]* %10, i64 0, i64 0
%40 = load i32, i32* %9
%41 = call i32 @bubble_sort(i32* %39, i32 %40)
store i32 0, i32* %7
br label %42
42: ; preds = %57, %38
%43 = load i32, i32* %7
%44 = load i32, i32* %9
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %60
46: ; preds = %42
%47 = load i32, i32* %7
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [101 x i32], [101 x i32]* %10, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %51
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %42
60: ; preds = %42
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %60
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
store i32 %64, i32* %8
br label %12
65: ; preds = %12
ret i32 0
}

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