// Arup Guha
// 11/21/2013
// Solution to 2013 Pacific North West Regional Problem C: Crusher's Code

import java.util.*;

public class c {

	public static int n;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Go through each case.
		for (int loop=0; loop<numCases; loop++) {

			// Read in array and make two copies.
			n = stdin.nextInt();
			int[] nums = new int[n];
			for (int i=0; i<n; i++)
				nums[i] = stdin.nextInt();
			int[] nums2 = Arrays.copyOf(nums, n);

			// Store a sorted copy.
			int[] sorted = getSorted(nums);

			// Set up storage to Monty subproblems and set up recursion.
			HashMap<String,Double> montyMap = new HashMap<String,Double>();
			montyMap.put(getString(sorted), 0.0);
			double monty = solveMonty(nums, montyMap);

			// Do Carlos here.
			HashMap<String,Double> carlosMap = new HashMap<String,Double>();
			carlosMap.put(getString(sorted), 0.0);
			double carlos = solveCarlos(nums2, carlosMap);

			// Output result.
			System.out.printf("Monty %.6f Carlos %.6f\n", monty, carlos);
		}
	}

	// Returns a sorted version of a without changing a.
	public static int[] getSorted(int[] a) {
		int[] b = new int[a.length];
		for (int i=0; i<a.length; i++)
			b[i] = a[i];
		Arrays.sort(b);
		return b;
	}

	// Returns a string version of a, adding commas after each element.
	public static String getString(int[] a) {
		String s = "";
		for (int i=0; i<a.length; i++)
			s = s + a[i] +",";
		return s;
	}

	// Returns the expected time for Carlos's algorithm to sort perm.
	public static double solveCarlos(int[] perm, HashMap<String,Double> map) {

		// We solved this already.
		String s = getString(perm);
		if (map.containsKey(s)) return map.get(s);

		// Go through each swap with probability 1/(n-1).
		double probNoChange = 0;
		double expRest = 0;
		for (int i=0; i<n-1; i++) {

			// Our state gets repeated.
			if (perm[i] <= perm[i+1])
				probNoChange = probNoChange+1.0/(n-1);

			// Build off easier cases.
			else {
				swap(perm, i, i+1);
				expRest = expRest + (1+solveCarlos(perm, map))/(n-1);
				swap(perm, i, i+1);
			}
		}

		// Solve the equation for this expection, store the answer and return.
		double ans = (probNoChange+expRest)/(1-probNoChange);
		map.put(s, ans);
		return ans;
	}

	// Returns the expected time for Monty's algorithm to sort perm.
	public static double solveMonty(int[] perm, HashMap<String,Double> map) {

		// We solved this already.
		String s = getString(perm);
		if (map.containsKey(s)) return map.get(s);

		// Go through each possible swap with probability 1/n^2.
		double probNoChange = 0;
		double expRest = 0;

		// Loop through each random index.
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {

				// Pick out which one is smaller, which one is larger...
				int minI = Math.min(i,j);
				int maxI = Math.max(i,j);

				// Our state gets repeated.
				if (perm[minI] <= perm[maxI])
					probNoChange = probNoChange+1.0/(n*n);

				// Build off easier cases.
				else {
					swap(perm, minI, maxI);
					expRest = expRest + (1+solveMonty(perm, map))/(n*n);
					swap(perm, minI, maxI);
				}
			}
		}

		// Solve the equation for this expection, store the answer and return.
		double ans = (probNoChange+expRest)/(1-probNoChange);
		map.put(s, ans);
		return ans;
	}

	public static void swap(int[] a, int i, int j) {
		int t = a[i];
		a[i] = a[j];
		a[j] = t;
	}
}