import java.util.Scanner;
public class P8958 {
public static void main(String[] args) {
int test,sum,score;
int result[];
char[] arr;
String str;
Scanner sc = new Scanner(System.in);
test = sc.nextInt();
result = new int[test];
for(int k = 0; k < test; k++) {
str = sc.next();
arr = new char[str.length()+1];
for(int i = 0 ; i < str.length(); i++ ) {
arr[i] = str.charAt(i);
}
sum = 0;
score = 1;
for(int i = 0; i < arr.length; i++) {
if(arr[i] == 'O') {
sum += score;
if(arr[i+1] == 'O') {
score ++;
}
else {
score = 1;
}
}
else {
score = 1;
}
}
result[k] = sum;
}
for(int i = 0; i < test; i++) {
System.out.println(result[i]);
}
sc.close();
}
}