#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int stringReduction(char *);
int main() {
  int res, t, i;
  scanf("%d", &t);
  int r[100];
  char a[100001];
  for (i = 0; i < t; i++) {
    memset(a, 0, 100001);
    scanf("%s", a);
    res = stringReduction(a);
    r[i] = res;
  }
  for (i = 0; i < t; i++) {
    printf("%d\n", r[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x18850,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ca <main+0x8a>
lea    -0x18850(%rbp),%rdi
xor    %esi,%esi
mov    $0x186a1,%edx
call   1040 <memset@plt>
lea    -0x18850(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x18850(%rbp),%rdi
call   1050 <stringReduction@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
movslq -0x10(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116b <main+0x2b>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1202 <main+0xc2>
movslq -0x10(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d1 <main+0x91>
xor    %eax,%eax
add    $0x18850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x18850,%rsp
lea    0xead(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ea <main+0xaa>
lea    0x1a0(%rsp),%r15
lea    0xe8a(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x186a1,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r15,%rdi
call   1050 <stringReduction@plt>
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1180 <main+0x40>
test   %eax,%eax
jle    11ea <main+0xaa>
xor    %ebx,%ebx
lea    0xe43(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11d0 <main+0x90>
xor    %eax,%eax
add    $0x18850,%rsp
pop    %rbx
pop    %r14
pop    %r15
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"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i32]
%6 = alloca [100001 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* %3)
store i32 0, i32* %4
br label %8
8: ; preds = %23, %0
%9 = load i32, i32* %4
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %26
12: ; preds = %8
%13 = getelementptr inbounds [100001 x i8], [100001 x i8]* %6, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 100001)
%15 = getelementptr inbounds [100001 x i8], [100001 x i8]* %6, i64 0, i64 0
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [100001 x i8], [100001 x i8]* %6, i64 0, i64 0
%18 = call i32 @stringReduction(i8* %17)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %21
store i32 %19, i32* %22
br label %23
23: ; preds = %12
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %8
26: ; preds = %8
store i32 0, i32* %4
br label %27
27: ; preds = %37, %26
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %31
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %27
40: ; preds = %27
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 [100 x i32]
%3 = alloca [100001 x i8]
%4 = bitcast i32* %1 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = bitcast [100 x i32]* %2 to i8*
%7 = getelementptr inbounds [100001 x i8], [100001 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %12, label %31
10: ; preds = %12
%11 = icmp sgt i32 %19, 0
br i1 %11, label %22, label %31
12: ; preds = %0, %12
%13 = phi i64 [ %18, %12 ], [ 0, %0 ]
%14 = call i32 @memset(i8* %7, i32 0, i32 100001)
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%16 = call i32 @stringReduction(i8* %7)
%17 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %13
store i32 %16, i32* %17
%18 = add nuw nsw i64 %13, 1
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %12, label %10
22: ; preds = %10, %22
%23 = phi i64 [ %27, %22 ], [ 0, %10 ]
%24 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %23, 1
%28 = load i32, i32* %1
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %22, label %31
31: ; preds = %22, %0, %10
ret i32 0
}