import java.io.*;
import java.util.*;
class Solution {
static char[] left = { '[', '{', '<', '(' };
static char[] right = { ']', '}', '>', ')' };
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = 10;
StringBuilder sb = new StringBuilder();
for (int test_case = 1; test_case <= T; test_case++) {
int n = Integer.parseInt(br.readLine());
String s = br.readLine();
Stack<Character> sl = new Stack<Character>();
int result = 1;
end: for (int i = 0; i < s.length(); i++) {
for (int j = 0; j < left.length; j++) {
if (left[j] == s.charAt(i)) {
sl.push(s.charAt(i));
break;
} else if (right[j] == s.charAt(i)) {
if (left[j] == sl.peek()) {
sl.pop();
} else {
result = 0;
break end;
}
}
}
}
result = sl.isEmpty() ? 1 : 0;
sb.append("#").append(test_case).append(" ").append(result).append("\n");
}
System.out.println(sb);
}
}