풀이시간: 26분
n = int(input())
while n > 0:
s = []
context = input()
while len(context) > 0:
top = context[0]
if len(s) != 0 and (s[-1] == '(' and top == ')'):
context = context.replace(context[0],'', 1)
s.pop(-1)
else:
context = context.replace(context[0],'', 1)
s.append(top)
if len(s) == 0:
print('YES')
else:
print('NO')
n -= 1
for _ in range(int(input())):
stk = []
isVPS = True
for ch in input():
if ch == '(':
stk.append(ch)
else:
if len(stk) > 0:
stk.pop()
else:
isVPS = False
break
if len(stk) > 0:
isVPS = False
print('YES' if isVPS else 'NO')