#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 *, char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main() {
  char oriDNA[101], temp[101], min[101], hold[101];
  int T, i, len;
  scanf("%d", &T);
  while (T--) {
    scanf("%s", oriDNA);
    strcpy(min, oriDNA);
    len = strlen(oriDNA);
    for (i = 1; i < len; i++) {
      strcpy(hold, oriDNA);
      strcpy(temp, hold + i);
      hold[i] = 0;
      strcat(temp, hold);
      if (strcmp(temp, min) < 0)
        strcpy(min, temp);
    }
    printf("%s\n", min);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    -0x1c4(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x1c4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c4(%rbp)
cmp    $0x0,%eax
je     129e <main+0x13e>
lea    -0x70(%rbp),%rsi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    -0x150(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1cc(%rbp)
movl   $0x1,-0x1c8(%rbp)
mov    -0x1c8(%rbp),%eax
cmp    -0x1cc(%rbp),%eax
jge    1286 <main+0x126>
lea    -0x1c0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xe0(%rbp),%rdi
lea    -0x1c0(%rbp),%rsi
movslq -0x1c8(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
movslq -0x1c8(%rbp),%rax
movb   $0x0,-0x1c0(%rbp,%rax,1)
lea    -0xe0(%rbp),%rdi
lea    -0x1c0(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0xe0(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jge    126d <main+0x10d>
lea    -0x150(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1272 <main+0x112>
mov    -0x1c8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c8(%rbp)
jmp    11dc <main+0x7c>
lea    -0x150(%rbp),%rsi
lea    0xd72(%rip),%rdi
call   1050 <printf@plt>
jmp    1187 <main+0x27>
xor    %eax,%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1c8,%rsp
lea    0xe88(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    119f <main+0x3f>
xor    %eax,%eax
add    $0x1c8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x160(%rsp),%r15
lea    0x80(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xf0(%rsp),%rbx
jmp    11d6 <main+0x76>
xchg   %ax,%ax
lea    0xe3f(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
subl   $0x1,0xc(%rsp)
jb     118b <main+0x2b>
lea    0xe26(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     11c0 <main+0x60>
mov    %eax,%ebp
add    $0xffffffffffffffff,%rbp
lea    0x11(%rsp),%r14
jmp    121a <main+0xba>
nopl   0x0(%rax)
add    $0x1,%r14
add    $0xffffffffffffffff,%rbp
je     11c0 <main+0x60>
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
movb   $0x0,(%r14)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jns    1210 <main+0xb0>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    1210 <main+0xb0>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [101 x i8]
%3 = alloca [101 x i8]
%4 = alloca [101 x i8]
%5 = alloca [101 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
br label %10
10: ; preds = %54, %0
%11 = load i32, i32* %6
%12 = add nsw i32 %11, -1
store i32 %12, i32* %6
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %57
14: ; preds = %10
%15 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %8
store i32 1, i32* %7
br label %22
22: ; preds = %51, %14
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %54
26: ; preds = %22
%27 = getelementptr inbounds [101 x i8], [101 x i8]* %5, i64 0, i64 0
%28 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
%31 = getelementptr inbounds [101 x i8], [101 x i8]* %5, i64 0, i64 0
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i32 @strcpy(i8* %30, i8* %34)
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [101 x i8], [101 x i8]* %5, i64 0, i64 %37
store i8 0, i8* %38
%39 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
%40 = getelementptr inbounds [101 x i8], [101 x i8]* %5, i64 0, i64 0
%41 = call i32 @strcat(i8* %39, i8* %40)
%42 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
%43 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%44 = call i64 @strcmp(i8* %42, i8* %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %26
%47 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%48 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
%49 = call i32 @strcpy(i8* %47, i8* %48)
br label %50
50: ; preds = %46, %26
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %22
54: ; preds = %22
%55 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%56 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %55)
br label %10
57: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [101 x i8]
%2 = alloca [101 x i8]
%3 = alloca [101 x i8]
%4 = alloca [101 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%10 = bitcast i32* %5 to i8*
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%12 = load i32, i32* %5
%13 = add nsw i32 %12, -1
store i32 %13, i32* %5
%14 = icmp eq i32 %12, 0
br i1 %14, label %40, label %15
15: ; preds = %0, %35
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%17 = call i32 @strcpy(i8* %8, i8* %6)
%18 = call i32 @strlen(i8* %6)
%19 = icmp sgt i32 %18, 1
br i1 %19, label %20, label %35
20: ; preds = %15
%21 = zext i32 %18 to i64
br label %22
22: ; preds = %20, %32
%23 = phi i64 [ 1, %20 ], [ %33, %32 ]
%24 = call i32 @strcpy(i8* %9, i8* %6)
%25 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 %23
%26 = call i32 @strcpy(i8* %7, i8* %25)
store i8 0, i8* %25
%27 = call i32 @strcat(i8* %7, i8* %9)
%28 = call i64 @strcmp(i8* %7, i8* %8)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = call i32 @strcpy(i8* %8, i8* %7)
br label %32
32: ; preds = %22, %30
%33 = add nuw nsw i64 %23, 1
%34 = icmp eq i64 %33, %21
br i1 %34, label %35, label %22
35: ; preds = %32, %15
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%37 = load i32, i32* %5
%38 = add nsw i32 %37, -1
store i32 %38, i32* %5
%39 = icmp eq i32 %37, 0
br i1 %39, label %40, label %15
40: ; preds = %35, %0
ret i32 0
}