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 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]
        try:
            t = S[i+3]
        except IndexError:
            break
        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((num_s, num_t))
        else:
            es.add((num_t, num_s))
    return es, cars


def main(args):
    n = int(input())
    for _ in range(n):
        S = input().strip()
        if len(S) < 4:
            print(S)
            continue

        es, cars = decode_txt(S)

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

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


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

Python: N = input()
for i in range(N):
  s = raw_input()
  p, r, l, a= 50, 50, 50, [s[0]]
  for c in s:
    if c == '-':
      pass
    elif c == '>':
      p += 1
    elif c == '<':
      p -= 1
    else:
      if p > r:
        a.append(c)
        r = p
      elif p < l:
        a.insert(0, c)
        l = p
  print(''.join(a))

Python: n = int(input())

for _ in range(n):
    record = input()
    record = list(record)

    ans = [record.pop(0)]
    while record != []:

        arrow = record.pop(0)
        record.pop(0)
        train = record.pop(0)

        if train not in ans:
            if arrow == "-":
                ans.append(train)
            else:
                ans.insert(0, train)

    print(''.join(str(a) for a in ans))

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:i] == '->' and train[-1] == seq[i - 3]:
            train = train + seq[i]
        if seq[i - 2:i] == '<-' and train[0] == seq[i - 3]:
            train = seq[i] + train
    print(train)

Python: n = int(input())
for i in range(n):
    
    Tr = list(input())
    cou = 0
    ans = [Tr[cou]]
    while len(Tr) -1 > cou:
        
        if Tr[cou + 1] == "-":
            if Tr[cou + 3] in ans:
                cou += 3
                continue
            else:
                ans = ans + [Tr[cou + 3]]
          
        else:
            if Tr[cou + 3] in ans:
                cou += 3
                continue
            else:
                ans = [Tr[cou + 3]] + ans
        cou += 3
    a_s = ""
    for i in range(len(ans)):
        a_s = a_s + ans[i]
    print(a_s)

Python: n=int(input())
for i in range(n):
    s=input()
    station_list=[]
    for si in s[::3]:
        station_list.append(si)
    st_l=list(dict.fromkeys(station_list))
    ans=[0]*51
    ans[25]=station_list[0]
    for j in st_l[1:]:
        place=s.index(j)
        now=s[place-3:place+1]
        if now[1:3]=="->":
            ans[ans.index(now[0])+1]=now[3]
        elif now[1:3]=="<-":
            ans[ans.index(now[0])-1]=now[3]
    ans_l=list(dict.fromkeys(ans))
    ans_l.remove(0)
    print(''.join(map(str,ans_l)))

Python: inputCount = int(input())

for _ in range(inputCount):

    inputContent = input()
    trainOrder = [item for item in inputContent if str.isalpha(item)]
    directOrder = [item for item in inputContent if item == "<" or item == ">"]

    trainList = []
    trainList.append(trainOrder[0])
    listIndex = 1
    trainLength = 1

    for train, direct in zip(trainOrder[1:], directOrder):

        if listIndex == 1 and direct == "<":
            trainList.insert(0, train)
            trainLength += 1
        elif listIndex == trainLength and direct == ">":
            trainList.append(train)
            listIndex += 1
            trainLength += 1

        elif direct == "<":
            listIndex -= 1
        else:
            listIndex += 1

    output = "".join(trainList)
    print(output)

Python: for _ in range(int(input())):
    s = input().replace("->", ">").replace("<-", "<")
    t, train, s = s[0], [s[0]], s[1:]
    for i in range(0, len(s), 2):
        if s[i] == '>' and not s[i+1] in train:
            idx = train.index(t)+1
            train.insert(idx, s[i+1])
        elif not s[i+1] in train:
             idx = train.index(t)
             train.insert(idx, s[i+1])
        t = s[i+1]
    print(''.join(train))

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define PB push_back

typedef pair<int, char> pic;
typedef vector<pic> vp;

int main() {
	int n;
	cin >> n;
	while (n--) {
		vp v;
		string str;
		cin >> str;
		
		v.PB(pic(0, str[0]));
		
		int tmp = 0;
		for(int i = 1; i < str.size(); i += 3) {
			if (str.substr(i, 2) == "<-") {
				tmp--;
				v.PB(pic(tmp, str[i + 2])); 
			}
			else {
				tmp++;
				v.PB(pic(tmp, str[i + 2]));
			}
		}
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		
		REP(i, v.size())
			printf("%c", v[i].second);
		cout << endl;
	}
	return 0;
}