//PairingParentheses
#include <stdio.h>
#include <iostream>
using namespace std;
int Qx[1000];
int f;
void init(){
f=0;
}
void push(int x){
f= f+1;
Qx[f] = x;
}
int valueInf(){
return Qx[f];
}
void pop(){
f = f-1;
// x=Qx[f];
}
int change(char c){
if(c == '(') return -1;
if(c == ')') return 1;
if(c == '[') return -2;
if(c == ']') return 2;
if(c == '{') return -3;
if(c == '}') return 3;
if(c == '<') return -4;
if(c == '>') return 4;
}
int main(){
int N, i, test_case, j, x, y;
freopen("PairingParentheses.txt", "r", stdin);
for(test_case=1; test_case<11; test_case++){
cin >> N;
cin.ignore();
char c[N];
int k;
for (int i=0;i<N;i++)
cin>>c[i];
init();
// for (int i=0;i<N;i++)
// cout<<c[i];
for(int i=0; i<N; i++){
k = change(c[i]);
// printf("f %d k = %d valueInf() = %d\n", f, k, valueInf());
if(i == 0){
push(k);
}
else{
if((k + valueInf())==0){
pop();
}else
if((k + valueInf())!=0){
push(k);
}
}
}
if(f<=0)
printf("#%d 1\n", test_case);
else
printf("#%d 0\n", test_case);
}
return 0;
}