#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 /*<<< orphan*/ scanf(char *, ...);
int strlen(char *);
scalar_t__ test(char *, int, int);
int main() {
  int T, n, i;
  char s[86];
  scanf("%d", &T);
  while (T--) {
    scanf("%s", s);
    n = strlen(s);
    for (i = 1; i <= n; ++i) {
      if (n % i == 0 && test(s, i, n / i)) {
        break;
      }
    }
    printf("%d\n", i);
    if (T)
      printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     121b <main+0xdb>
lea    -0x70(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11ed <main+0xad>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11da <main+0x9a>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,%edx
call   1060 <test@plt>
cmp    $0x0,%rax
je     11da <main+0x9a>
jmp    11ed <main+0xad>
jmp    11df <main+0x9f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119a <main+0x5a>
mov    -0x10(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
je     1216 <main+0xd6>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1161 <main+0x21>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe9b(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,0xc(%rsp)
jb     123d <main+0xed>
lea    0x10(%rsp),%r12
lea    0xe7e(%rip),%r15
nopl   0x0(%rax,%rax,1)
lea    0xe6c(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1210 <main+0xc0>
mov    %eax,%r14d
lea    0x1(%r14),%ebp
mov    %eax,%r13d
neg    %r13d
mov    $0x1,%ebx
jmp    11e3 <main+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%rbx,%r13,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     1200 <main+0xb0>
mov    %r14d,%eax
cltd
idiv   %ebx
test   %edx,%edx
jne    11d0 <main+0x80>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1070 <test@plt>
test   %rax,%rax
je     11d0 <main+0x80>
jmp    1215 <main+0xc5>
mov    %ebp,%ebx
jmp    1215 <main+0xc5>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x1,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
je     123d <main+0xed>
mov    $0xa,%edi
call   1030 <putchar@plt>
subl   $0x1,0xc(%rsp)
jae    1190 <main+0x40>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [86 x i8]
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %7
7: ; preds = %45, %0
%8 = load i32, i32* %2
%9 = add nsw i32 %8, -1
store i32 %9, i32* %2
%10 = icmp ne i32 %8, 0
br i1 %10, label %11, label %46
11: ; preds = %7
%12 = getelementptr inbounds [86 x i8], [86 x i8]* %5, i64 0, i64 0
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [86 x i8], [86 x i8]* %5, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %3
store i32 1, i32* %4
br label %16
16: ; preds = %35, %11
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %16
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = srem i32 %21, %22
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %20
%26 = getelementptr inbounds [86 x i8], [86 x i8]* %5, i64 0, i64 0
%27 = load i32, i32* %4
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = sdiv i32 %28, %29
%31 = call i64 @test(i8* %26, i32 %27, i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %25
br label %38
34: ; preds = %25, %20
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %16
38: ; preds = %33, %16
%39 = load i32, i32* %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %2
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43, %38
br label %7
46: ; preds = %7
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"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [86 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [86 x i8], [86 x i8]* %2, i64 0, i64 0
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %36, label %9
9: ; preds = %0, %31
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%11 = call i32 @strlen(i8* %4)
%12 = icmp slt i32 %11, 1
br i1 %12, label %26, label %13
13: ; preds = %9
%14 = add nuw i32 %11, 1
br label %15
15: ; preds = %13, %23
%16 = phi i32 [ %24, %23 ], [ 1, %13 ]
%17 = srem i32 %11, %16
%18 = sdiv i32 %11, %16
%19 = icmp eq i32 %17, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = call i64 @test(i8* %4, i32 %16, i32 %18)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %15, %20
%24 = add nuw i32 %16, 1
%25 = icmp eq i32 %16, %11
br i1 %25, label %26, label %15
26: ; preds = %23, %20, %9
%27 = phi i32 [ 1, %9 ], [ %16, %20 ], [ %14, %23 ]
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %1
%30 = icmp eq i32 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %26
%32 = call i32 @putchar(i32 10)
%33 = load i32, i32* %1
%34 = add nsw i32 %33, -1
store i32 %34, i32* %1
%35 = icmp eq i32 %33, 0
br i1 %35, label %36, label %9
36: ; preds = %31, %26, %0
ret i32 0
}