https://www.acmicpc.net/problem/5397
import sys
input = sys.stdin.readline
test_case = int(input())
for _ in range(test_case):
pw = list(input().rstrip('\n'))
left = []
right = []
i = 0
for i in pw:
if i == '<':
if left:
right.append(left.pop())
elif i == '>':
if right:
left.append(right.pop())
elif i == '-':
if left:
left.pop()
else:
left.append(i)
left.extend(reversed(right))
print(''.join(left))
백준 1406번과 같은 방식으로 풀면 된다 !