#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 cases, prisonerCount, sweetCount, id, poison;
  scanf("%d", &cases);
  for (int i = 0; i < cases; i++) {
    scanf("%d", &prisonerCount);
    scanf("%d", &sweetCount);
    scanf("%d", &id);
    poison = (id + sweetCount - 1) % prisonerCount;
    if (poison == 0) {
      printf("%d\n", prisonerCount);
    } else {
      printf("%d\n", poison);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d2 <main+0xb2>
lea    0xea7(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe97(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe87(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11b0 <main+0x90>
mov    -0xc(%rbp),%esi
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
jmp    11bf <main+0x9f>
mov    -0x18(%rbp),%esi
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
jmp    11c4 <main+0xa4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1146 <main+0x26>
mov    -0x4(%rbp),%eax
add    $0x20,%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    0xecb(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11be <main+0x9e>
xor    %ebp,%ebp
lea    0xeb1(%rip),%rbx
lea    0x14(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0xe9e(%rip),%r13
jmp    1181 <main+0x61>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jge    11be <main+0x9e>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
mov    0x10(%rsp),%ecx
add    %ecx,%eax
add    $0xffffffff,%eax
mov    0x14(%rsp),%esi
cltd
idiv   %esi
test   %edx,%edx
je     1170 <main+0x50>
mov    %edx,%esi
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 = [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
store i32 0, i32* %1
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %7
br label %9
9: ; preds = %32, %0
%10 = load i32, i32* %7
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %35
13: ; preds = %9
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = add nsw i32 %17, %18
%20 = sub nsw i32 %19, 1
%21 = load i32, i32* %3
%22 = srem i32 %20, %21
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %13
%26 = load i32, i32* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %31
28: ; preds = %13
%29 = load i32, i32* %6
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %28, %25
br label %32
32: ; preds = %31
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %9
35: ; preds = %9
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [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 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %13, %0
ret i32 0
13: ; preds = %0, %13
%14 = phi i32 [ %27, %13 ], [ 0, %0 ]
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = add i32 %18, -1
%21 = add i32 %20, %19
%22 = load i32, i32* %2
%23 = srem i32 %21, %22
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i32 %22, i32 %23
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i32 %14, 1
%28 = load i32, i32* %1
%29 = icmp slt i32 %27, %28
br i1 %29, label %13, label %12
}