// Arup Guha
// 3/18/2016
// Solution to 2014 NY Regional Problem B: Islands in the Data Stream

import java.util.*;

public class b {

	final public static int SIZE = 12;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=1; loop<=numCases; loop++) {

			// Read in data.
			int caseNum = stdin.nextInt();
			int[] vals = new int[SIZE];
			for (int i=0; i<SIZE; i++) vals[i] = stdin.nextInt();

			// Just check every possible interval to see if it's an island or not.
			int res = 0;
			for (int i=1; i<SIZE-1; i++) {
				for (int j=i; j<SIZE-1; j++) {
					int thisM = min(vals, i, j);
					if (thisM > vals[i-1] && thisM > vals[j+1])
						res++;
				}
			}

			// Output result.
			System.out.println(caseNum+" "+res);
		}
	}

	// Returns the minimum of a[low..high].
	public static int min(int[] a, int low, int high) {
		int res = a[low];
		for (int i=low+1; i<=high; i++)
			res = Math.min(res, a[i]);
		return res;
	}
}
