const input = require("fs").readFileSync(0, "utf8").toString().trim().split('\n');
for(let i=1; i<=Number(input[0]); i++) {
    const Str = input[i];
    let [score, res] = [0, 0];
    for(let s of Str) {
        if(s==='O') {
            score++;
            res += score;
        }
        else if(score!==0) {
            score=0;
        }
    }
    console.log(res);
}