#53763: 答案


s310037@student.cysh.cy.edu.tw (辛吉飛(林恩丞))

學校 : 不指定學校
編號 : 281575
來源 : [163.27.3.94]
最後登入時間 :
2025-10-01 09:33:32

for i in range(int(input())):
    s =[]
    for j in input():
        if j in '{(<[':
            s+=[j]
        elif s and s[-1] == '([<{'[')]>}'.find(j)]:
            s.pop()
        else:
            break

    else:
        if not s:
            print('Y')
            continue

    print('N')