#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 main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long int n, m, s;
    scanf("%ld %ld %ld", &n, &m, &s);
    int r = (s + m - 1) % n;
    if (0 == r) {
      printf("%ld\n", n);
    } else {
      printf("%d\n", r);
    }
  }
  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>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11bc <main+0x9c>
lea    0xea7(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
sub    $0x1,%rax
cqto
idivq  -0x10(%rbp)
mov    %edx,%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
jne    11a8 <main+0x88>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
jmp    11b7 <main+0x97>
mov    -0x24(%rbp),%esi
lea    0xe62(%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   %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>
subl   $0x1,0xc(%rsp)
jae    1159 <main+0x39>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xea3(%rip),%r14
lea    0x20(%rsp),%r15
lea    0x18(%rsp),%r12
lea    0x10(%rsp),%rbx
lea    0xe99(%rip),%r13
lea    0xe97(%rip),%rbp
jmp    1191 <main+0x71>
nop
mov    %rbp,%rdi
mov    %edx,%esi
call   1030 <printf@plt>
subl   $0x1,0xc(%rsp)
jb     1148 <main+0x28>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%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     11e0 <main+0xc0>
cqto
idiv   %rsi
test   %edx,%edx
jne    1180 <main+0x60>
jmp    11e8 <main+0xc8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edx,%edx
div    %esi
test   %edx,%edx
jne    1180 <main+0x60>
mov    %r13,%rdi
jmp    1185 <main+0x65>

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