// Arup Guha
// 3/26/2021
// Solution to 2021 Code Jam Qualifying Question: Revsort
import java.util.*;

public class Solution {

	public static void main(String[] args) {
	
		// Get # of cases.
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process cases.
		for (int loop=1; loop<=nC; loop++) {
		
			int n = stdin.nextInt();
			int[] arr = new int[n];
			
			// Read in the array.
			for (int i=0; i<n; i++)
				arr[i] = stdin.nextInt();
				
			int res = 0;
			
			// Go through the steps.
			for (int i=0; i<n-1; i++) {
			
				// Find min index.
				int minI = i;
				for (int j=i+1; j<n; j++) 
					if (arr[j] < arr[minI]) minI = j;
				
				// Add to cost.
				res += (minI - i + 1);
			
				// Reverse.
				for (int j=i,k=minI; j<k; j++,k--) {
					int tmp = arr[j];
					arr[j] = arr[k];
					arr[k] = tmp;
				}
			}
			
			// Ta da!
			System.out.println("Case #"+loop+": "+res);
		}
	}
}