import java.util.Scanner;
public class Main {
public static int calc(int n) {
return (((n*n) + n) / 2);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tcase = sc.nextInt();
String text = sc.nextLine();
String[] list = new String[tcase];
for (int i = 0; i < tcase; i++) {
int score = 0;
int plus = 0;
list[i] = sc.nextLine();
char[] temp = list[i].toCharArray();
for (int j = 0; j < temp.length; j++) {
if (temp[j] == 'O') {
plus++;
}
else {
score += calc(plus);
plus = 0;
}
if (j + 1 == temp.length) {
score += calc(plus);
plus = 0;
}
}
System.out.println(score);
}
}
}