// Arup Guha
// 12/15/2016
// Solution to 2016 Online HS Problem: Infinite Keyboard

import java.util.*;

public class keyboard {

	final public static String[] notes1 = {"A","A#","B","C","C#","D","D#","E","F","F#","G","G#"};
	final public static String[] notes2 = {"A", "Bb", "B","C","Db","D","Eb","E","F","Gb","G","Ab"};

	public static void main(String[] args) {

		// Make reverse lookup.
		HashMap<String,Integer> map = new HashMap<String,Integer>();
		for (int i=0; i<notes1.length; i++) {
			map.put(notes1[i], i);
			map.put(notes2[i], i);
		}

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=1; loop<=numCases; loop++) {

			// Read in number of notes;
			int n = stdin.nextInt();
			int res = 0;

			// Get first note.
			int cur = map.get(stdin.next());

			// Now count gaps and add.
			for (int i=1; i<n; i++) {
				int next = map.get(stdin.next());
				int jump = Math.abs(cur-next);
				res +=Math.min(jump, 12-jump);
				cur = next;
			}

			// Output result.
			System.out.println("Song #"+loop+": "+res);
		}
	}
}