T = int(input())
for _ in range(T):
underflow = 0
stack = []
line = list(input())
for word in line:
if word == '(':
stack.append(word)
elif word == ')':
if len(stack) == 0:
underflow = 1
break
stack.pop()
if len(stack) == 0 and underflow != 1:
print('YES')
else:
print('NO')
알고리즘