#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 *, long *, ...);
int main() {
  long n, m, s, t;
  scanf("%ld", &t);
  while (t--) {
    scanf("%ld %ld %ld", &n, &m, &s);
    long result = (m + s - 1) % n;
    if (result != 0) {
      printf("%ld\n", result);
    } else {
      printf("%ld\n", n);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed2(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
cmp    $0x0,%rax
je     11bf <main+0x9f>
lea    0xe9f(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
sub    $0x1,%rax
cqto
idivq  -0x10(%rbp)
mov    %rdx,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11aa <main+0x8a>
mov    -0x30(%rbp),%rsi
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
jmp    11ba <main+0x9a>
mov    -0x10(%rbp),%rsi
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xed4(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subq   $0x1,(%rsp)
jae    1155 <main+0x35>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xea4(%rip),%r14
lea    0x18(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0xe9a(%rip),%rbx
jmp    118f <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <printf@plt>
subq   $0x1,(%rsp)
jb     1145 <main+0x25>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    0x18(%rsp),%rsi
mov    %rax,%rcx
or     %rsi,%rcx
shr    $0x20,%rcx
je     11d0 <main+0xb0>
cqto
idiv   %rsi
test   %rdx,%rdx
je     1180 <main+0x60>
jmp    11d9 <main+0xb9>
xor    %edx,%edx
div    %esi
test   %rdx,%rdx
je     1180 <main+0x60>
mov    %rdx,%rsi
jmp    1180 <main+0x60>

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\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 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %5)
br label %8
8: ; preds = %28, %0
%9 = load i64, i64* %5
%10 = add nsw i64 %9, -1
store i64 %10, i64* %5
%11 = icmp ne i64 %9, 0
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64* %2, i64* %3, i64* %4)
%14 = load i64, i64* %3
%15 = load i64, i64* %4
%16 = add nsw i64 %14, %15
%17 = sub nsw i64 %16, 1
%18 = load i64, i64* %2
%19 = srem i64 %17, %18
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = load i64, i64* %6
%24 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %23)
br label %28
25: ; preds = %12
%26 = load i64, i64* %2
%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, %22
br label %8
29: ; preds = %8
ret i32 0
}

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