1. 
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 11786 - Global Raining at Bididibus
* Link: 11786 - Global Raining at Bididibus
*
* @author Evgeni Pavlidis
* @version 1.0, 06/02/2010
*
* Method : Ad hoc
* Status : Accepted
* Runtime: 0.228
*/

import java.io.*;
import java.util.*;

class Main {

public static void main(String...args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int testCases = Integer.parseInt(reader.readLine());
Stack<Integer> stack = new Stack<Integer>();
int sum;

String input;
for(int t = 0; t < testCases; t++)
{
input = reader.readLine();

stack.clear();
sum = 0;

for(int i = 0; i < input.length(); i++)
if(input.charAt(i) == '/' && !stack.empty())
sum += i - stack.pop();
else
if(input.charAt(i) == '\\')
stack.push(i);

System.out.println(sum);
}
}
}