#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() {
  int T, i, cnt, cnt2;
  char c[85];
  scanf("%d", &T);
  while (T > 0, T--) {
    scanf("%s", &c);
    cnt = 0;
    cnt2 = 0;
    for (i = 0; c[i] != '\0'; ++i) {
      if (c[i] == 'O')
        cnt += ++cnt2;
      else
        cnt2 = 0;
    }
    printf("%d\n", cnt);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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
je     11e2 <main+0xc2>
lea    0xea7(%rip),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11ce <main+0xae>
movslq -0xc(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x4f,%eax
jne    11b4 <main+0x94>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11bb <main+0x9b>
movl   $0x0,-0x14(%rbp)
jmp    11c0 <main+0xa0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117c <main+0x5c>
mov    -0x10(%rbp),%esi
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xece(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    1153 <main+0x33>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xea9(%rip),%r14
lea    0x10(%rsp),%r12
lea    0xea0(%rip),%r15
jmp    1181 <main+0x61>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
subl   $0x1,0xc(%rsp)
jb     1145 <main+0x25>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %r12,%rax
xor    %ecx,%ecx
jmp    11ac <main+0x8c>
nopw   0x0(%rax,%rax,1)
add    %ecx,%ebx
add    $0x1,%ebx
add    $0x1,%ecx
add    $0x1,%rax
movzbl (%rax),%edx
cmp    $0x4f,%dl
je     11a0 <main+0x80>
test   %dl,%dl
je     1170 <main+0x50>
xor    %ecx,%ecx
add    $0x1,%rax
jmp    11ac <main+0x8c>

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 i32
%6 = alloca [85 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* %2)
br label %8
8: ; preds = %41, %0
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
%11 = zext i1 %10 to i32
%12 = load i32, i32* %2
%13 = add nsw i32 %12, -1
store i32 %13, i32* %2
%14 = icmp ne i32 %12, 0
br i1 %14, label %15, label %44
15: ; preds = %8
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [85 x i8]* %6)
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %3
br label %17
17: ; preds = %38, %15
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [85 x i8], [85 x i8]* %6, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %17
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [85 x i8], [85 x i8]* %6, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 79
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
%34 = load i32, i32* %4
%35 = add nsw i32 %34, %33
store i32 %35, i32* %4
br label %37
36: ; preds = %24
store i32 0, i32* %5
br label %37
37: ; preds = %36, %31
br label %38
38: ; preds = %37
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %17
41: ; preds = %17
%42 = load i32, i32* %4
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %8
44: ; preds = %8
%45 = load i32, i32* %1
ret i32 %45
}

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 [85 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [85 x i8], [85 x i8]* %2, i64 0, i64 0
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %29, label %9
9: ; preds = %0, %24
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [85 x i8]* %2)
br label %11
11: ; preds = %20, %9
%12 = phi i64 [ %23, %20 ], [ 0, %9 ]
%13 = phi i32 [ %21, %20 ], [ 0, %9 ]
%14 = phi i32 [ %22, %20 ], [ 0, %9 ]
%15 = getelementptr inbounds [85 x i8], [85 x i8]* %2, i64 0, i64 %12
%16 = load i8, i8* %15
switch i8 %16, label %20 [
i8 0, label %24
i8 79, label %17
]
17: ; preds = %11
%18 = add nsw i32 %14, 1
%19 = add nsw i32 %18, %13
br label %20
20: ; preds = %11, %17
%21 = phi i32 [ %19, %17 ], [ %13, %11 ]
%22 = phi i32 [ %18, %17 ], [ 0, %11 ]
%23 = add nuw i64 %12, 1
br label %11
24: ; preds = %11
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%26 = load i32, i32* %1
%27 = add nsw i32 %26, -1
store i32 %27, i32* %1
%28 = icmp eq i32 %26, 0
br i1 %28, label %29, label %9
29: ; preds = %24, %0
ret i32 0
}