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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x186c0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1234 <main+0xe4>
lea    -0x186c0(%rbp),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    -0x186c0(%rbp),%rdi
call   1050 <plndrm@plt>
cmp    $0x0,%rax
je     11c6 <main+0x76>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122f <main+0xdf>
lea    -0x186c0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122a <main+0xda>
lea    -0x186c0(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <plndrm1@plt>
cmp    $0x0,%rax
je     1217 <main+0xc7>
mov    -0x14(%rbp),%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122a <main+0xda>
jmp    121c <main+0xcc>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11dc <main+0x8c>
jmp    122f <main+0xdf>
jmp    1174 <main+0x24>
xor    %eax,%eax
add    $0x186c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x186b8,%rsp
lea    0xe88(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    119f <main+0x3f>
xor    %eax,%eax
add    $0x186b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5d(%rip),%r14
lea    0x10(%rsp),%r13
lea    0xe54(%rip),%r15
lea    0xe51(%rip),%r12
jmp    11cf <main+0x6f>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <puts@plt>
subl   $0x1,0xc(%rsp)
jb     118b <main+0x2b>
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    %r13,%rdi
call   1060 <plndrm@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c8 <main+0x68>
mov    %eax,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %ebx,%esi
call   1070 <plndrm1@plt>
test   %rax,%rax
jne    1218 <main+0xb8>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1200 <main+0xa0>
jmp    11c8 <main+0x68>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c8 <main+0x68>

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

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