#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 *, long);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    long int n, m, s;
    scanf("%ld %ld %ld", &n, &m, &s);
    long int x = (s + m - 1) % n;
    if (!x) {
      x = n;
    }
    printf("%ld\n", x);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b5 <main+0x95>
lea    0xea8(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
sub    $0x1,%rax
cqto
idivq  -0x18(%rbp)
mov    %rdx,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1197 <main+0x77>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1148 <main+0x28>
xor    %eax,%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    $0x28,%rsp
lea    0xecb(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11de <main+0xbe>
lea    0xeb0(%rip),%r14
lea    0x20(%rsp),%r15
lea    0x18(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xea6(%rip),%rbx
xor    %ebp,%ebp
jmp    1181 <main+0x61>
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jge    11de <main+0xbe>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%rax
mov    0x18(%rsp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    0x20(%rsp),%rsi
mov    %rax,%rcx
or     %rsi,%rcx
shr    $0x20,%rcx
je     11d0 <main+0xb0>
cqto
idiv   %rsi
test   %rdx,%rdx
je     1170 <main+0x50>
jmp    11d9 <main+0xb9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edx,%edx
div    %esi
test   %rdx,%rdx
je     1170 <main+0x50>
mov    %rdx,%rsi
jmp    1170 <main+0x50>
xor    %eax,%eax
add    $0x28,%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 = [12 x i8] c"%ld %ld %ld\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %9
9: ; preds = %28, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64* %4, i64* %5, i64* %6)
%15 = load i64, i64* %6
%16 = load i64, i64* %5
%17 = add nsw i64 %15, %16
%18 = sub nsw i64 %17, 1
%19 = load i64, i64* %4
%20 = srem i64 %18, %19
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = icmp ne i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %13
%24 = load i64, i64* %4
store i64 %24, i64* %7
br label %25
25: ; preds = %23, %13
%26 = load i64, i64* %7
%27 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %26)
br label %28
28: ; preds = %25
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %9
31: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [12 x i8] c"%ld %ld %ld\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i32* %1 to i8*
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = bitcast i64* %2 to i8*
%11 = bitcast i64* %3 to i8*
%12 = bitcast i64* %4 to i8*
br label %14
13: ; preds = %14, %0
ret i32 0
14: ; preds = %9, %14
%15 = phi i32 [ 0, %9 ], [ %26, %14 ]
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64* %2, i64* %3, i64* %4)
%17 = load i64, i64* %4
%18 = load i64, i64* %3
%19 = add i64 %17, -1
%20 = add i64 %19, %18
%21 = load i64, i64* %2
%22 = srem i64 %20, %21
%23 = icmp eq i64 %22, 0
%24 = select i1 %23, i64 %21, i64 %22
%25 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %24)
%26 = add nuw nsw i32 %15, 1
%27 = load i32, i32* %1
%28 = icmp slt i32 %26, %27
br i1 %28, label %14, label %13
}