#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 root_of_square(int, int, int);
int /*<<< orphan*/ scanf(char *, ...);
scalar_t__ strlen(char *);
int main() {
  int n;
  scanf("%d", &n);
  char buffer[20002];
  char *out = buffer + 10001;
  while (n--) {
    int index = 0;
    scanf("%s", buffer);
    int len = (int)strlen(buffer);
    int sqr = root_of_square(len, 1, 100);
    for (int i = sqr - 1; i >= 0; i--) {
      for (int j = i; j < len; j += sqr) {
        out[index++] = buffer[j];
      }
    }
    out[index] = '\0';
    printf("%s\n", out);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x4e30(%rbp),%rax
add    $0x2711,%rax
mov    %rax,-0x4e38(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1298 <main+0x158>
movl   $0x0,-0x4e3c(%rbp)
lea    -0x4e30(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x4e30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4e40(%rbp)
mov    -0x4e40(%rbp),%edi
mov    $0x1,%esi
mov    $0x64,%edx
call   1050 <root_of_square@plt>
mov    %eax,-0x4e44(%rbp)
mov    -0x4e44(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4e48(%rbp)
cmpl   $0x0,-0x4e48(%rbp)
jl     126e <main+0x12e>
mov    -0x4e48(%rbp),%eax
mov    %eax,-0x4e4c(%rbp)
mov    -0x4e4c(%rbp),%eax
cmp    -0x4e40(%rbp),%eax
jge    1255 <main+0x115>
movslq -0x4e4c(%rbp),%rax
mov    -0x4e30(%rbp,%rax,1),%dl
mov    -0x4e38(%rbp),%rax
mov    -0x4e3c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x4e3c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4e44(%rbp),%eax
add    -0x4e4c(%rbp),%eax
mov    %eax,-0x4e4c(%rbp)
jmp    1200 <main+0xc0>
jmp    125a <main+0x11a>
mov    -0x4e48(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4e48(%rbp)
jmp    11e7 <main+0xa7>
mov    -0x4e38(%rbp),%rax
movslq -0x4e3c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x4e38(%rbp),%rsi
lea    0xd78(%rip),%rdi
call   1040 <printf@plt>
jmp    1178 <main+0x38>
xor    %eax,%eax
add    $0x4e50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e38,%rsp
lea    0xea8(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    117f <main+0x3f>
xor    %eax,%eax
add    $0x4e38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x2721(%rsp),%r13
lea    0x10(%rsp),%r15
lea    0xe73(%rip),%r12
jmp    11bd <main+0x7d>
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebp,%rax
movb   $0x0,0x2721(%rsp,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
subl   $0x1,0xc(%rsp)
jb     116b <main+0x2b>
xor    %ebp,%ebp
lea    0xe3d(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
mov    %r14d,%edi
mov    $0x1,%esi
mov    $0x64,%edx
call   1050 <root_of_square@plt>
test   %eax,%eax
jle    11a0 <main+0x60>
mov    %eax,%eax
movslq %r14d,%rcx
xor    %ebp,%ebp
mov    %rax,%r8
jmp    1205 <main+0xc5>
nopl   (%rax)
cmp    $0x2,%esi
jl     11a0 <main+0x60>
mov    %r8d,%esi
add    $0xffffffffffffffff,%r8
cmp    %r14d,%esi
jg     1200 <main+0xc0>
movslq %ebp,%rdi
add    %r13,%rdi
mov    %r8,%rdx
nopw   0x0(%rax,%rax,1)
movzbl 0x10(%rsp,%rdx,1),%ebx
mov    %bl,(%rdi)
add    %rax,%rdx
add    $0x1,%rdi
add    $0x1,%ebp
cmp    %rcx,%rdx
jl     1220 <main+0xe0>
jmp    1200 <main+0xc0>

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 i32
%3 = alloca [20002 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = getelementptr inbounds [20002 x i8], [20002 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds i8, i8* %11, i64 10001
store i8* %12, i8** %4
br label %13
13: ; preds = %54, %0
%14 = load i32, i32* %2
%15 = add nsw i32 %14, -1
store i32 %15, i32* %2
%16 = icmp ne i32 %14, 0
br i1 %16, label %17, label %61
17: ; preds = %13
store i32 0, i32* %5
%18 = getelementptr inbounds [20002 x i8], [20002 x i8]* %3, i64 0, i64 0
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [20002 x i8], [20002 x i8]* %3, i64 0, i64 0
%21 = call i64 @strlen(i8* %20)
%22 = trunc i64 %21 to i32
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = call i32 @root_of_square(i32 %23, i32 1, i32 100)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = sub nsw i32 %25, 1
store i32 %26, i32* %8
br label %27
27: ; preds = %51, %17
%28 = load i32, i32* %8
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %54
30: ; preds = %27
%31 = load i32, i32* %8
store i32 %31, i32* %9
br label %32
32: ; preds = %46, %30
%33 = load i32, i32* %9
%34 = load i32, i32* %6
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %50
36: ; preds = %32
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [20002 x i8], [20002 x i8]* %3, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = load i8*, i8** %4
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 %40, i8* %45
br label %46
46: ; preds = %36
%47 = load i32, i32* %7
%48 = load i32, i32* %9
%49 = add nsw i32 %48, %47
store i32 %49, i32* %9
br label %32
50: ; preds = %32
br label %51
51: ; preds = %50
%52 = load i32, i32* %8
%53 = add nsw i32 %52, -1
store i32 %53, i32* %8
br label %27
54: ; preds = %27
%55 = load i8*, i8** %4
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 0, i8* %58
%59 = load i8*, i8** %4
%60 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %59)
br label %13
61: ; preds = %13
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 i32
%2 = alloca [20002 x i8]
%3 = bitcast i32* %1 to i8*
%4 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = getelementptr inbounds [20002 x i8], [20002 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [20002 x i8], [20002 x i8]* %2, i64 0, i64 10001
%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 %51, label %10
10: ; preds = %0, %34
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%12 = call i64 @strlen(i8* %5)
%13 = trunc i64 %12 to i32
%14 = call i32 @root_of_square(i32 %13, i32 1, i32 100)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %10
%17 = zext i32 %14 to i64
%18 = shl i64 %12, 32
%19 = ashr exact i64 %18, 32
br label %25
20: ; preds = %42
%21 = trunc i64 %47 to i32
br label %22
22: ; preds = %20, %25
%23 = phi i32 [ %28, %25 ], [ %21, %20 ]
%24 = icmp sgt i32 %27, 1
br i1 %24, label %25, label %34
25: ; preds = %16, %22
%26 = phi i64 [ %17, %16 ], [ %29, %22 ]
%27 = phi i32 [ %14, %16 ], [ %30, %22 ]
%28 = phi i32 [ 0, %16 ], [ %23, %22 ]
%29 = add nsw i64 %26, -1
%30 = add nsw i32 %27, -1
%31 = icmp sgt i32 %27, %13
br i1 %31, label %22, label %32
32: ; preds = %25
%33 = sext i32 %28 to i64
br label %42
34: ; preds = %22, %10
%35 = phi i32 [ 0, %10 ], [ %23, %22 ]
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %6, i64 %36
store i8 0, i8* %37
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%39 = load i32, i32* %1
%40 = add nsw i32 %39, -1
store i32 %40, i32* %1
%41 = icmp eq i32 %39, 0
br i1 %41, label %51, label %10
42: ; preds = %32, %42
%43 = phi i64 [ %33, %32 ], [ %47, %42 ]
%44 = phi i64 [ %29, %32 ], [ %49, %42 ]
%45 = getelementptr inbounds [20002 x i8], [20002 x i8]* %2, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = add nsw i64 %43, 1
%48 = getelementptr inbounds i8, i8* %6, i64 %43
store i8 %46, i8* %48
%49 = add i64 %44, %17
%50 = icmp slt i64 %49, %19
br i1 %50, label %42, label %20
51: ; preds = %34, %0
ret i32 0
}