#53762: 答案


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

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

答案

t=int(input())
for i in range(t):
    a=list(input())
    i=0
    count=0
    stack=[]
    for _ in range(len(a)):
        if(a[i]!=' '):

            stack.append(a[i])
        
        if(len(stack)>1):
            if(stack[len(stack)-2]=="("and  stack[len(stack)-1]==")"):
                del  stack[len(stack)-2:len(stack)]
                count+=1
        i+=1
        
    if(len(stack)>0):
        count=0
        
 

    print(count)