n=int(input());stack=[]
for i in range(n):
word=input();count=0
for j in range(len(word)-1):
if (len(stack)!=0 and stack[-1]=="(" and word[j]==")" ):
stack.pop()
count+=1
else:
stack.append(word[j])
if (len(stack)!=0):count=0
print(count)