각 괄호 수를 count해서 비교하는 방법도 있지만 stack이라는 단원에 맞게 pop을 사용하였다.
for tc in range(1,10+1):
n = int(input())
arr=list(input())
chk=[]
res=1
for i in arr:
if i==')':
if chk[-1]=='(':
chk.pop()
continue
elif i=='}':
if chk[-1]=='{':
chk.pop()
continue
elif i=='>':
if chk[-1]=='<':
chk.pop()
continue
elif i==']':
if chk[-1]=='[':
chk.pop()
continue
chk.append(i)
if chk:
res=0
print(f'#{tc} {res}')