#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 n, i;
  char s[100];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    int j, count = 0, sum = 0;
    scanf("%s", s);
    for (j = 0; s[j] != 0; j++) {
      if (s[j] == 'O')
        count++;
      else
        count = 0;
      sum += count;
    }
    printf("%d\n", sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11eb <main+0xcb>
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x74(%rbp)
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11ce <main+0xae>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x4f,%eax
jne    11b0 <main+0x90>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    11b7 <main+0x97>
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
add    -0x7c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    117e <main+0x5e>
mov    -0x7c(%rbp),%esi
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <main+0x2b>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
lea    0xeca(%rip),%rdi
xor    %ebp,%ebp
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ab <main+0x8b>
lea    0xeb1(%rip),%r14
lea    0x10(%rsp),%r12
lea    0xea8(%rip),%r15
xchg   %ax,%ax
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %r12,%rax
xor    %esi,%esi
jmp    1189 <main+0x69>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebx
add    %ebx,%esi
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x4f,%cl
je     1180 <main+0x60>
mov    $0x0,%ebx
test   %cl,%cl
jne    1183 <main+0x63>
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jl     1160 <main+0x40>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
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 [100 x i8]
%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* %2)
store i32 0, i32* %3
br label %9
9: ; preds = %44, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %47
13: ; preds = %9
store i32 0, i32* %6
store i32 0, i32* %7
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 0, i32* %5
br label %16
16: ; preds = %38, %13
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %41
23: ; preds = %16
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 79
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %34
33: ; preds = %23
store i32 0, i32* %6
br label %34
34: ; preds = %33, %30
%35 = load i32, i32* %6
%36 = load i32, i32* %7
%37 = add nsw i32 %36, %35
store i32 %37, i32* %7
br label %38
38: ; preds = %34
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %16
41: ; preds = %16
%42 = load i32, i32* %7
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %41
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %9
47: ; preds = %9
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 i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 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 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %28
8: ; preds = %0, %23
%9 = phi i32 [ %25, %23 ], [ 0, %0 ]
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %11
11: ; preds = %19, %8
%12 = phi i64 [ %22, %19 ], [ 0, %8 ]
%13 = phi i32 [ %20, %19 ], [ 0, %8 ]
%14 = phi i32 [ %21, %19 ], [ 0, %8 ]
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %12
%16 = load i8, i8* %15
switch i8 %16, label %19 [
i8 0, label %23
i8 79, label %17
]
17: ; preds = %11
%18 = add nsw i32 %13, 1
br label %19
19: ; preds = %11, %17
%20 = phi i32 [ %18, %17 ], [ 0, %11 ]
%21 = add nsw i32 %20, %14
%22 = add nuw i64 %12, 1
br label %11
23: ; preds = %11
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%25 = add nuw nsw i32 %9, 1
%26 = load i32, i32* %1
%27 = icmp slt i32 %25, %26
br i1 %27, label %8, label %28
28: ; preds = %23, %0
ret i32 0
}