tc = int(input())
for i in range(tc):
n = int(input())
a = input()
count1 = 0
s = []
k = []
for i in range(len(a)):
k.append(a[i])
for i in range(len(k)):
if(k[i]=='_' and count1==0):
k[i] = '('
elif(k[i]=='_'):
k[i] = ')'
count1-=1
elif(k[i]=='('):
count1+=1
ans = 0
for i in range(len(k)):
if(k[i]=='('):
ans -=(i+1)
else:
ans +=(i+1)
print(ans)
1718C - Tonya and Burenka-179 | 834A - The Useless Toy |
1407D - Discrete Centrifugal Jumps | 1095B - Array Stabilization |
291B - Command Line Arguments | 1174B - Ehab Is an Odd Person |
624B - Making a String | 1064C - Oh Those Palindromes |
1471A - Strange Partition | 1746A - Maxmina |
1746B - Rebellion | 66C - Petya and File System |
1746C - Permutation Operations | 1199B - Water Lily |
570B - Simple Game | 599C - Day at the Beach |
862A - Mahmoud and Ehab and the MEX | 1525A - Potion-making |
1744D - Divisibility by 2n | 1744A - Number Replacement |
1744C - Traffic Light | 1744B - Even-Odd Increments |
637B - Chat Order | 546C - Soldier and Cards |
18D - Seller Bob | 842B - Gleb And Pizza |
1746D - Paths on the Tree | 1651E - Sum of Matchings |
19A - World Football Cup | 630P - Area of a Star |