#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*/ free(int *);
int getMaxIncreasingSubSequence(char *, int /*<<< orphan*/, int, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  char str[1000];
  int *pal;
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", str);
    int len = 0, i = 0;
    while (str[i++] != '\0') {
      len++;
    }
    int col = len, x, y;
    pal = (int *)malloc(sizeof(int) * len);
    for (x = 0; x < len; x++) {
      pal[x] = 1;
    }
    printf("%d\n", getMaxIncreasingSubSequence(str, 0, len, pal));
    free(pal);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    -0x3fc(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x3fc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x3fc(%rbp)
cmp    $0x0,%eax
je     1296 <main+0x146>
lea    -0x3f0(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x400(%rbp)
movl   $0x0,-0x404(%rbp)
mov    -0x404(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x404(%rbp)
cltq
movsbl -0x3f0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     11f2 <main+0xa2>
mov    -0x400(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x400(%rbp)
jmp    11ba <main+0x6a>
mov    -0x400(%rbp),%eax
mov    %eax,-0x408(%rbp)
movslq -0x400(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x3f8(%rbp)
movl   $0x0,-0x40c(%rbp)
mov    -0x40c(%rbp),%eax
cmp    -0x400(%rbp),%eax
jge    125c <main+0x10c>
mov    -0x3f8(%rbp),%rax
movslq -0x40c(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x40c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40c(%rbp)
jmp    1221 <main+0xd1>
lea    -0x3f0(%rbp),%rdi
mov    -0x400(%rbp),%edx
mov    -0x3f8(%rbp),%rcx
xor    %esi,%esi
call   1070 <getMaxIncreasingSubSequence@plt>
mov    %eax,%esi
lea    0xd86(%rip),%rdi
call   1040 <printf@plt>
mov    -0x3f8(%rbp),%rdi
call   1030 <free@plt>
jmp    1177 <main+0x27>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
lea    0xea8(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    118f <main+0x3f>
xor    %eax,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe7d(%rip),%r14
lea    0x10(%rsp),%r12
lea    0xe74(%rip),%r15
jmp    11e4 <main+0x94>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %r12,%rdi
xor    %esi,%esi
mov    %ebx,%edx
mov    %r13,%rcx
call   1070 <getMaxIncreasingSubSequence@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
subl   $0x1,0xc(%rsp)
jb     117b <main+0x2b>
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpb   $0x0,0x10(%rsp)
je     11b0 <main+0x60>
xor    %edi,%edi
mov    $0x1,%eax
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%ebp
add    $0x4,%edi
cmpb   $0x0,0x11(%rsp,%rbx,1)
lea    0x1(%rbx),%rbx
lea    0x1(%rbp),%eax
jne    1210 <main+0xc0>
call   1050 <malloc@plt>
mov    %rax,%r13
test   %ebx,%ebx
je     1240 <main+0xf0>
mov    %ebx,%eax
mov    %ebp,%ecx
cmp    $0x8,%rax
jae    1247 <main+0xf7>
xor    %eax,%eax
jmp    1290 <main+0x140>
nopl   (%rax)
xor    %ebx,%ebx
jmp    11bc <main+0x6c>
mov    %ebx,%edx
and    $0x7,%edx
sub    %rdx,%rax
and    $0x7,%ebp
mov    %rcx,%rsi
sub    %rbp,%rsi
xor    %edi,%edi
movaps 0xd9f(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movups %xmm0,0x0(%r13,%rdi,4)
movups %xmm0,0x10(%r13,%rdi,4)
add    $0x8,%rdi
cmp    %rdi,%rsi
jne    1270 <main+0x120>
test   %rdx,%rdx
je     11bc <main+0x6c>
xchg   %ax,%ax
movl   $0x1,0x0(%r13,%rax,4)
add    $0x1,%rax
cmp    %rax,%rcx
jne    1290 <main+0x140>
jmp    11bc <main+0x6c>

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