// Arup Guha
// 5/2/2014
// Solution to UCF HS Contest Problem: Fishy Business

import java.util.*;
import java.io.*;

public class fishy {

	public static void main(String[] args) throws Exception {

		Scanner fin = new Scanner(new File("fishy.in"));

		// Process all cases.
		int numCases = fin.nextInt();
		for (int loop=1; loop<=numCases; loop++) {
			int n = fin.nextInt();
			String fish = fin.next();
			System.out.println("Day #"+loop+": "+solve(fish)+" rubles");
		}
		fin.close();
	}

	// Solves problem by looking for both types of fish.
	public static int solve(String fish) {
		return solveForward(fish) + solveBackward(fish);
	}

	// Returns score of forward fish, facing the right.
	public static int solveForward(String fish) {

		int index = fish.indexOf(')');
		int score = 0;

		// Go until no more fish are found.
		while (index != -1) {

			// Go to the end of the supposed fish body.
			int end = index;
			while (end < fish.length() && fish.charAt(end) == ')') end++;

			// Avoid array out of bounds...
			if (index >= 2 && end <= fish.length()-2) {

				// Check left and right of the body, add if it's a fish!
				if (fish.substring(index-2,index).equals("><") && fish.substring(end,end+2).equals("o>") )
					score += (end-index)*(end-index);
			}

			// Go to next body part.
			index = fish.indexOf(')',end+1);
		}

		return score;
	}

	// Returns score of forward fish, facing the left.
	public static int solveBackward(String fish) {

		int index = fish.indexOf('(');
		int score = 0;

		// Go until no more fish are found.
		while (index != -1) {

			// Go to the end of the supposed fish body.
			int end = index;
			while (end < fish.length() && fish.charAt(end) == '(') end++;

			// Avoid array out of bounds.
			if (index >= 2 && end <= fish.length()-2) {

				// Check left and right of the body, add if it's a fish!
				if (fish.substring(index-2,index).equals("<o") && fish.substring(end,end+2).equals("><") )
					score += (end-index)*(end-index);
			}

			// Go to next body part.
			index = fish.indexOf('(',end+1);
		}

		return score;
	}
}