


S = input().strip()
temp = ''
l_stack = []
for i in S:
    # print(temp)
    if "<" in i:
        if temp:
            l_stack.append(temp)
        temp = ''
        temp += i
    elif ">" in i:
        temp += i
        l_stack.append(temp)
        temp = ''
    else:
        temp += i
if temp:
    l_stack.append(temp)
for i in l_stack:
    if "<" in i:
        print(i, end="")
    else:
        new = [x[::-1] for x in i.split()]
        print(' '.join(new), end="")
print()

S, tmp = input(), ""
ck = False
for i in S:
	if i == ' ':
    	if not ck:
        	print(temp[::-1], end = " ")
            tmp = ""
        else:
        	print(" ", end = "")
   	elif i == '<':
    	ck = True
        print(tmp[::-1] + "<", end = "")
        tmp = ""
    elif i == '>':
    	ck = False
        print(">", end = "")
    else: # 알파벳과 숫자
    	if ck:
        	print(i, end="")
        else:
        	temp += i
print(tmp[::-1], end=" ")