import java.util.Scanner;
import java.util.Stack;
class Solution {
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner(System.in);
for (int testCase = 1; testCase <= 10; testCase++) {
int n = sc.nextInt();
int flag = 1;
char[] arr = sc.next().toCharArray();
Stack<Character> stack = new Stack<>();
for (int i = 0; i < n; i++) {
if (arr[i] == '(' || arr[i] == '[' || arr[i] == '{' || arr[i] == '<') {
stack.push(arr[i]);
}
else {
char temp = stack.pop();
if ((temp == '(' && arr[i] != ')') || (temp == '<' && arr[i] != '>') || (temp == '{' && arr[i] != '}') || (temp == '[' && arr[i] != ']')) {
flag = 0;
break;
}
}
}
System.out.printf("#%d %d\n", testCase, flag);
}
}
}
스택을 생성후 여는괄호일땐 push, 닫는괄호일때 짝이 맞는지 확인하고 맞지않으면 break후 flag 출력