Go: package main

import (
	"bufio"
	"os"
	"unicode"
	"strconv"
	"fmt"
	"strings"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		s := strings.Split(scanner.Text(), "")
		ans, dir := make([]string, 0), ">"
		for _, x := range s {
			if IsLetter(x) {
				if dir == ">" {
					if !isIn(ans, x) {
						ans = append(ans, x)
					}
				} else {
					if !isIn(ans, x) {
						ans = append([]string{x}, ans...)
					}
				}
			} else if x == ">" || x == "<" {
				dir = x
			}
		}
		fmt.Println(strings.Join(ans, ""))
	}
}

func IsLetter(s string) bool {
	for _, r := range s {
		if !unicode.IsLetter(r) {
			return false
		}
	}
	return true
}

func isIn(arr []string, target string) bool {
	for _, val := range arr {
		if val == target {
			return true
		}
	}
	return false
}

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0130

"""
import sys
from sys import stdin
input = stdin.readline
from collections import namedtuple
from collections import deque


def bfs(u, result, out_edge, in_degree, processed):
    # ?????????????????????????????¨??????????????¢??°
    q = deque()
    q.append(u)
    processed[u] = True
    while q:
        u = q.popleft()
        result.append(u)
        for e in out_edge[u]:
            in_degree[e] -= 1   #  ?????¨?????????????????????(u)?????????????????¨???u?????\?¶????(e)????????\????¬???°???1???????????¨?????????
            if in_degree[e] == 0 and processed[e] == False: #  ??\????¬???°???1??????????????????0???????????°??????????????????????¬??????????????£??????????
                processed[e] = True
                q.append(e)


def solve(V, in_degree, out_edge):
    # ????????????????????????????????????????????????
    result = []
    processed = [False for _ in range(V)] #  ???????????????????????????????????????????????°
    for i, u in enumerate(in_degree):
        if u == 0 and processed[i] == False: #  ??\????¬???°???0???????????????
            bfs(i, result, out_edge, in_degree, processed)
    return result


def decode_txt(S):
    # ??\????????????????????????????§£???????????¨???????????±??¨?????´?????????????????±?????????
    es = set()
    cars = set()                #  ??????(?????????)?????°
    l = len(S)

    # ???????????????l -> ??? <- ?????¨???????????±?????????
    for i in range(l):
        if not 'a' <= S[i] <='z':
            continue
        s = S[i]
        t = S[i+3]
        num_s = ord(s) - ord('a') #  ???????¨????'a'???0?????¨????????????????????°????????????
        num_t = ord(t) - ord('a')
        cars.add(num_s)
        cars.add(num_t)
        if S[i+1] == '-':
            es.add(edge(num_s, num_t))
        else:
            es.add(edge(num_t, num_s))
        if i + 3 + 1 == l:
            break
    return es, cars


edge = namedtuple('edge', ['f', 't'])
def main(args):
    # S = 'b->a->c<-a->c->d<-c<-a<-b->a->c->d->e<-d'
    n = int(input())
    for _ in range(n):
        S = input().strip()
        es, cars = decode_txt(S)

        V = len(cars)
        in_degree = [0 for _ in range(V)] #  ????????????????????\????¬???°
        out_edge = [[] for _ in range(V)] #  ???????????????????????????(??\?¶?)?????????????????????
        for s, t in es:
            out_edge[s].append(t)
            in_degree[t] += 1

        result = solve(V, in_degree, out_edge)
        txt = [chr(x+ord('a')) for x in result] #  ??°???????????????????????? (???: 0->'a')
        print(''.join(txt))


if __name__ == '__main__':
    main(sys.argv[1:])

Python: n = int(input())
for _ in range(n):
  s = input()
  rec = [None] * 52
  ind = 25
  rec[ind] = s[0]
  max_ind = 25
  min_ind = 25

  for i in range(1, len(s), 3):
    direct = s[i:i + 2]
    if direct == "->":
      ind += 1
      max_ind = max(ind, max_ind)
    else:
      ind -= 1
      min_ind = min(ind, min_ind)
    rec[ind] = s[i + 2]

  print("".join(rec[min_ind:max_ind + 1]))

Python: n = int(input())

for _ in range(n):
    train = ''
    seq = input()
    for i in range(0, len(seq), 3):
        if i == 0:
            train += seq[i]
        if seq[i - 2] == '-' and train[-1] == seq[i - 3]:
            train = train + seq[i]
        if seq[i - 2] == '<' and train[0] == seq[i - 3]:
            train = seq[i] + train
    print(train)

Python: import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


SIZE = 3001
MID = 1500


N = int(input())
table = [None]*SIZE

for _ in range(N):
    for i in range(SIZE):
        table[i] = '@'

    input_str = input()

    table[MID] = input_str[0]
    loc = 0

    for i in range(1,len(input_str)-2,3):
        if input_str[i] == '-': #右へ
            loc += 1
            table[MID+loc] = input_str[i+2]
        else: #左へ
            loc -= 1
            table[MID+loc] = input_str[i+2]

    for i in range(SIZE):
        if table[i] == '@':
            continue
        print("%s"%(table[i]),end="")
    print()

Python: n=int(input())
for _ in range(n):
    s=input()
    s=s.replace("-","")
    train=["" for i in range(60)]
    pointer=30
    for i in s:
        if i=="<":
            pointer-=1
        elif i==">":
            pointer+=1
        else:
            train[pointer]=i
    print("".join(train))

Python: n = int(input())

for i in range(0,n):
    datas = input()
    dic = dict()
    sIndex = inIndex = isMove = 0

    while sIndex < len(datas):
        if not isMove:
            dic[datas[sIndex]] = inIndex
            sIndex += 2
        else:
            if datas[sIndex] == '>':
                inIndex += 1
            else:
                inIndex -= 1
            sIndex += 1
        isMove = not isMove

    dic = {k: v for k, v in sorted(dic.items(), key=lambda item: item[1])}
    for k in dic.keys():
        print(k,end="")
    print()

Python: n = int(input())

for _ in range(n):
    train = ''
    seq = input()
    for i in range(len(seq) // 3 + 1):
        if i == 0:
            train += seq[i]
        if seq[3 * i - 2] == '-' and train[-1] == seq[3 * (i - 1)]:
            train = train + seq[3 * i]
        if seq[3 * i - 2] == '<' and train[0] == seq[3 * (i - 1)]:
            train = seq[3 * i] + train
    print(train)