#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 t;
  int n, m, s, i;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d", &n, &m, &s);
    m = m % n;
    if (m == 0)
      m = n;
    if ((s + m - 1) <= n)
      printf("%d\n", (s + m - 1));
    else
      printf("%d\n", (s + m - 1 - n));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed0(%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     11d2 <main+0xb2>
lea    0xea4(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1189 <main+0x69>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
sub    $0x1,%eax
cmp    -0xc(%rbp),%eax
jg     11b5 <main+0x95>
mov    -0x14(%rbp),%esi
add    -0x10(%rbp),%esi
sub    $0x1,%esi
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
jmp    11cd <main+0xad>
mov    -0x14(%rbp),%esi
add    -0x10(%rbp),%esi
sub    $0x1,%esi
sub    -0xc(%rbp),%esi
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xed2(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    1157 <main+0x37>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xea2(%rip),%r14
lea    0xc(%rsp),%r15
mov    %rsp,%r12
lea    0x8(%rsp),%r13
lea    0xe97(%rip),%rbx
jmp    1191 <main+0x71>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
sub    %ecx,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     1147 <main+0x27>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    (%rsp),%eax
mov    0xc(%rsp),%ecx
cltd
idiv   %ecx
mov    %ecx,%eax
test   %edx,%edx
je     11b6 <main+0x96>
mov    %edx,%eax
mov    %eax,(%rsp)
mov    0x8(%rsp),%edx
lea    (%rax,%rdx,1),%esi
add    $0xffffffff,%esi
cmp    %ecx,%esi
jg     1180 <main+0x60>
xor    %ecx,%ecx
jmp    1180 <main+0x60>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@.str.2 = [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
store i32 0, i32* %1
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %42, %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 %43
12: ; preds = %8
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = srem i32 %14, %15
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = load i32, i32* %3
store i32 %20, i32* %4
br label %21
21: ; preds = %19, %12
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = add nsw i32 %22, %23
%25 = sub nsw i32 %24, 1
%26 = load i32, i32* %3
%27 = icmp sle i32 %25, %26
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load i32, i32* %5
%30 = load i32, i32* %4
%31 = add nsw i32 %29, %30
%32 = sub nsw i32 %31, 1
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %42
34: ; preds = %21
%35 = load i32, i32* %5
%36 = load i32, i32* %4
%37 = add nsw i32 %35, %36
%38 = sub nsw i32 %37, 1
%39 = load i32, i32* %3
%40 = sub nsw i32 %38, %39
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %34, %28
br label %8
43: ; preds = %8
ret i32 0
}

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