// Arup Guha
// 3/16/2017
// Solution to 2017 UCF HS Contest Problem: Shifting Gears

import java.util.*;

public class shift {
	
	// Store these here for convenience.
	final public static String SHIFTKEYS = "~!@#$%^&*()_+{}|:\"<>?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numCases = Integer.parseInt(stdin.nextLine());
		
		// Process each case.
		for (int loop=0; loop<numCases; loop++) {
			String line = stdin.nextLine();
			
			// Keep track of presses and what happened previously.
			int res = 0;
			boolean prev = false;
			
			// Go through each character.
			for (int i=0; i<line.length(); i++) {
				
				// Woohoo - we get to use contains again...
				if (SHIFTKEYS.contains(""+line.charAt(i)) && !prev) {
					res++;
					prev = true;
				}
				
				// Here we just turn the flag off.
				else if (!SHIFTKEYS.contains(""+line.charAt(i)))
					prev = false;
			}
					
			// Output result.
			System.out.println("The shift key was pressed "+res+" times.");
		}
	}
}