// Arup Guha
// 10/20/12 - 10/24/12
// Solution to Greater NY Regional Problem F: Monkey Vines

import java.util.*;

public class f {


	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		int numCases = Integer.parseInt(stdin.nextLine().trim());

		for (int loop=1; loop<=numCases; loop++) {
			String s = stdin.nextLine();
			System.out.println(loop+" "+solve(s, 0, s.length()-1));
		}
	}

	// Recursively solves the problem for s[start..end].
	public static int solve(String s, int start, int end) {

		// Easy base cases.
		if (start >= end)
			return 1;
		else if (end - start == 1)
			return 2;
			
		// Solve recursively.
		else {

			// There must be two sets of matching brackets, this finds the first set.
			int cnt = 1;
			int index = start+1;
			while (cnt != 0) {
				index++;
				if (s.charAt(index) == ']')
					cnt--;
				else
					cnt++;
			}

			// Whichever answer is higher, we must make the other side equal it, so
			// just multiply the larger side by 2.
			return 2*Math.max(solve(s, start+1, index), solve(s, index+1, end-1));
		}

	}
}