#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 getMaxpalindrome(char *, int /*<<< orphan*/, int, 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 * len);
    for (x = 0; x < len; x++) {
      for (y = 0; y < len; y++) {
        *(pal + x * col + y) = -1;
      }
    }
    printf("%d\n", getMaxpalindrome(str, 0, len - 1, pal, col));
    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     12f7 <main+0x1a7>
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
movslq -0x400(%rbp),%rcx
imul   %rcx,%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    12b3 <main+0x163>
movl   $0x0,-0x410(%rbp)
mov    -0x410(%rbp),%eax
cmp    -0x400(%rbp),%eax
jge    129a <main+0x14a>
mov    -0x3f8(%rbp),%rax
mov    -0x40c(%rbp),%ecx
imul   -0x408(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x410(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x410(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x410(%rbp)
jmp    1248 <main+0xf8>
jmp    129f <main+0x14f>
mov    -0x40c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40c(%rbp)
jmp    122c <main+0xdc>
lea    -0x3f0(%rbp),%rdi
mov    -0x400(%rbp),%edx
sub    $0x1,%edx
mov    -0x3f8(%rbp),%rcx
mov    -0x408(%rbp),%r8d
xor    %esi,%esi
call   1070 <getMaxpalindrome@plt>
mov    %eax,%esi
lea    0xd25(%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   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
lea    0xe89(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    119d <main+0x3d>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe5f(%rip),%r14
lea    0x10(%rsp),%r12
lea    0xe56(%rip),%r15
jmp    11ec <main+0x8c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x1(%rbx),%edx
mov    %r12,%rdi
xor    %esi,%esi
mov    %r13,%rcx
mov    %ebx,%r8d
call   1080 <getMaxpalindrome@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
subl   $0x1,0xc(%rsp)
jb     118a <main+0x2a>
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmpb   $0x0,0x10(%rsp)
mov    $0x0,%ebx
je     121b <main+0xbb>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,0x11(%rsp,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1210 <main+0xb0>
mov    %ebx,%edi
imul   %ebx,%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
test   %ebx,%ebx
je     11c0 <main+0x60>
mov    %ebx,%edx
imul   %rdx,%rdx
shl    $0x2,%rdx
mov    %r13,%rdi
mov    $0xff,%esi
call   1050 <memset@plt>
jmp    11c0 <main+0x60>

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 = %66, %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 %76
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 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = mul i64 %33, %35
%37 = trunc i64 %36 to i32
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i32*
store i32* %39, i32** %3
store i32 0, i32* %8
br label %40
40: ; preds = %63, %29
%41 = load i32, i32* %8
%42 = load i32, i32* %5
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %66
44: ; preds = %40
store i32 0, i32* %9
br label %45
45: ; preds = %59, %44
%46 = load i32, i32* %9
%47 = load i32, i32* %5
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %62
49: ; preds = %45
%50 = load i32*, i32** %3
%51 = load i32, i32* %8
%52 = load i32, i32* %7
%53 = mul nsw i32 %51, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %50, i64 %54
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
store i32 -1, i32* %58
br label %59
59: ; preds = %49
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
br label %45
62: ; preds = %45
br label %63
63: ; preds = %62
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %40
66: ; preds = %40
%67 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%68 = load i32, i32* %5
%69 = sub nsw i32 %68, 1
%70 = load i32*, i32** %3
%71 = load i32, i32* %7
%72 = call i32 @getMaxpalindrome(i8* %67, i32 0, i32 %69, i32* %70, i32 %71)
%73 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %72)
%74 = load i32*, i32** %3
%75 = call i32 @free(i32* %74)
br label %11
76: ; 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 %41, label %9
9: ; preds = %0, %33
%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 %21, label %13
13: ; preds = %9, %13
%14 = phi i64 [ %15, %13 ], [ 0, %9 ]
%15 = add nuw nsw i64 %14, 1
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %13
19: ; preds = %13
%20 = trunc i64 %15 to i32
br label %21
21: ; preds = %19, %9
%22 = phi i32 [ 0, %9 ], [ %20, %19 ]
%23 = shl i32 %22, 2
%24 = mul i32 %23, %22
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i32*
%27 = icmp eq i32 %22, 0
br i1 %27, label %33, label %28
28: ; preds = %21
%29 = inttoptr i64 %25 to i8*
%30 = zext i32 %22 to i64
%31 = mul nuw i64 %30, %30
%32 = shl i64 %31, 2
br label %33
33: ; preds = %28, %21
%34 = add nsw i32 %22, -1
%35 = call i32 @getMaxpalindrome(i8* %3, i32 0, i32 %34, i32* %26, i32 %22)
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = call i32 @free(i32* %26)
%38 = load i32, i32* %2
%39 = add nsw i32 %38, -1
store i32 %39, i32* %2
%40 = icmp eq i32 %38, 0
br i1 %40, label %41, label %9
41: ; preds = %33, %0
ret i32 0
}