#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*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  char vet[51];
  int n, l, hash;
  int i, j;
  scanf("%d", &n);
  do {
    hash = 0;
    scanf("%d", &l);
    for (i = 0; i < l; i++) {
      scanf("%50s", vet);
      for (j = 0; vet[j]; j++) {
        hash += (vet[j] - 65) + i + j;
      }
    }
    printf("%d\n", hash);
    n--;
  } while (n > 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x44(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x4c(%rbp)
lea    0xeb1(%rip),%rdi
lea    -0x48(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x48(%rbp),%eax
jge    11ce <main+0xae>
lea    -0x40(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x54(%rbp)
movslq -0x54(%rbp),%rax
cmpb   $0x0,-0x40(%rbp,%rax,1)
je     11bb <main+0x9b>
movslq -0x54(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
sub    $0x41,%eax
add    -0x50(%rbp),%eax
add    -0x54(%rbp),%eax
add    -0x4c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1186 <main+0x66>
jmp    11c0 <main+0xa0>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1161 <main+0x41>
mov    -0x4c(%rbp),%esi
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jg     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    $0x48,%rsp
lea    0xecb(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0x11(%rsp),%r14
lea    0xeb6(%rip),%r12
lea    0x10(%rsp),%rbx
jmp    1182 <main+0x62>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xea1(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
cmp    $0x1,%eax
jle    11ff <main+0xdf>
lea    0xe77(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
mov    $0x0,%ebp
jle    1160 <main+0x40>
xor    %r15d,%r15d
mov    $0xffffffbe,%r13d
xor    %ebp,%ebp
jmp    11bf <main+0x9f>
xchg   %ax,%ax
add    $0x1,%r15d
add    $0x1,%r13d
cmp    0x8(%rsp),%r15d
jge    1160 <main+0x40>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%dl
test   %dl,%dl
je     11b0 <main+0x90>
mov    %r14,%rcx
mov    %r13d,%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    11e0 <main+0xc0>
add    %eax,%esi
mov    %esi,%ebp
jmp    11b0 <main+0x90>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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