#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 */
typedef int /*<<< orphan*/ palavra;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  int casos, quantidadeDeLinhas, indiceDaLinha, indiceDaPalavra, hash;
  char palavra[64];
  scanf("%d\n", &casos);
  while (casos-- > 0) {
    hash = 0;
    scanf("%d\n", &quantidadeDeLinhas);
    for (indiceDaLinha = 0; indiceDaLinha < quantidadeDeLinhas;
         indiceDaLinha++) {
      scanf("%s\n", palavra);
      indiceDaPalavra = 0;
      while (palavra[indiceDaPalavra] != '\0') {
        hash += ((palavra[indiceDaPalavra]) - 'A') + indiceDaLinha +
                indiceDaPalavra;
        indiceDaPalavra++;
      }
    }
    printf("%d\n", hash);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
jle    11f9 <main+0xd9>
movl   $0x0,-0x18(%rbp)
lea    0xe9d(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e5 <main+0xc5>
lea    -0x60(%rbp),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11d2 <main+0xb2>
movslq -0x14(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
sub    $0x41,%eax
add    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119a <main+0x7a>
jmp    11d7 <main+0xb7>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1175 <main+0x55>
mov    -0x18(%rbp),%esi
lea    0xe11(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xecb(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
test   %eax,%eax
jle    120f <main+0xef>
lea    0xea5(%rip),%rbx
lea    0xea2(%rip),%r12
lea    0x10(%rsp),%r13
jmp    1190 <main+0x70>
nopl   0x0(%rax)
lea    0xe89(%rip),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
test   %eax,%eax
jle    120f <main+0xef>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
mov    $0x0,%ebp
lea    0x11(%rsp),%rbx
jle    1170 <main+0x50>
xor    %ebp,%ebp
mov    $0xffffffbe,%r14d
xor    %r15d,%r15d
jmp    11cf <main+0xaf>
nopl   (%rax)
add    $0x1,%r15d
add    $0x1,%r14d
cmp    0xc(%rsp),%r15d
jge    1170 <main+0x50>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%dl
test   %dl,%dl
je     11c0 <main+0xa0>
mov    %rbx,%rcx
mov    %r14d,%eax
nopw   0x0(%rax,%rax,1)
movsbl %dl,%esi
add    %ebp,%esi
lea    (%rax,%rsi,1),%ebp
add    $0x1,%ebp
movzbl (%rcx),%edx
add    $0x1,%eax
add    $0x1,%rcx
test   %dl,%dl
jne    11f0 <main+0xd0>
add    %eax,%esi
mov    %esi,%ebp
jmp    11c0 <main+0xa0>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [64 x i8]
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %48, %0
%10 = load i32, i32* %2
%11 = add nsw i32 %10, -1
store i32 %11, i32* %2
%12 = icmp sgt i32 %10, 0
br i1 %12, label %13, label %51
13: ; preds = %9
store i32 0, i32* %6
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 0, i32* %4
br label %15
15: ; preds = %45, %13
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %48
19: ; preds = %15
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 0, i32* %5
br label %22
22: ; preds = %29, %19
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %44
29: ; preds = %22
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = sub nsw i32 %34, 65
%36 = load i32, i32* %4
%37 = add nsw i32 %35, %36
%38 = load i32, i32* %5
%39 = add nsw i32 %37, %38
%40 = load i32, i32* %6
%41 = add nsw i32 %40, %39
store i32 %41, i32* %6
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %22
44: ; preds = %22
br label %45
45: ; preds = %44
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %15
48: ; preds = %15
%49 = load i32, i32* %6
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %49)
br label %9
51: ; preds = %9
ret i32 0
}

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