import java.io.*;
import java.util.*;
import java.util.regex.*;

public class Spam
{
    public static void main(String[] args)
    {
	Scanner in = new Scanner(System.in);
	PrintStream out = System.out;

	String address = "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9._]+\\.[a-zA-Z]{2,4}";
	Pattern pattern = Pattern.compile(address);

	int N = in.nextInt();
	in.nextLine();
	for (int n = 0; n < N; n++)
	{
	    String line = in.nextLine();
	    Matcher matcher = pattern.matcher(line);
	    int count = 0;
	    while (matcher.find())
	    {
		count++;
	    }
	    out.println(count);
	}
    }
}
