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
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  string gomi;
  cin.ignore();
  while (n--) {
    string s;
    getline(cin, s);
    vc a;
    vs b;
    rep(i, s.size() / 3) {
      a.pb(s.substr(i * 3, 1)[0]);
      b.pb(s.substr(i * 3 + 1, 2));
    }
    a.pb(s.back());
    vi t(26, -1), f(26);
    loop(i, 1, a.size()) {
      if (b[i - 1] == "->") {
        t[a[i - 1] - 'a']                              = a[i] - 'a';
        if (f[a[i - 1] - 'a'] != -1) f[a[i - 1] - 'a'] = 1;
        f[a[i] - 'a']                                  = -1;
      } else {
        t[a[i] - 'a']                          = a[i - 1] - 'a';
        if (f[a[i] - 'a'] != -1) f[a[i] - 'a'] = 1;
        f[a[i - 1] - 'a']                      = -1;
      }
    }
    // for (int i = distance(f.begin(), find(all(f), 1)); i != -1; i = t[i]) {
    //   cout << char(i + 'a');
    // }
    int i = distance(f.begin(), find(all(f), 1));
    // for (;;) {
    //   cout << char(i + 'a');
    //   i = t[i];
    //   if (i == -1) break;
    // }
    cout << endl;
  }
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<char, char> P;

int main() {
  int N; cin >>N;
  REP(n, N){
    string str; cin >>str;
    map<char, P> m;
    set<char> s;
    for(int i = 0; i + 3 < (int)(str.length()); i += 3){
      char c = str[i], next = str[i + 3];
      if(s.find(c) == s.end()) m[c] = P('A', 'A');
      if(s.find(next) == s.end()) m[next] = P('A', 'A');
      s.insert(c);
      s.insert(next);
      if(str[i + 2] == '>'){
        m[c].second = next;
        m[next].first = c;
      } else{
        m[c].first = next;
        m[next].second = c;
      }
    }
    char now = 'A';
    for(map<char, P>::iterator it = m.begin(); it != m.end(); ++it) if(it->second.first == 'A') now = it->first;
    while(now != 'A'){
      cout <<now;
      now = m[now].second;
    }
    cout <<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(){
	int n,pos;
	char train[60];
	string s;
	cin >> n;
	getchar();
	for(int i = 0;i < n;i++){
		pos = 30;
		for(int j = 0;j < 60;j++) train[j] = 0;
		getline(cin,s);
		train[pos] = s[0];
		for(int j = 1;j < s.size();j++){
			if(s[j] == '-') {
				j += 2;
				train[++pos] = s[j];
			}
			else if(s[j] == '<'){
				j += 2;
				train[--pos] = s[j];
			}
		}
		for(int j = 0;j < 60;j++){
			cout << train[j];
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <map>
int main(){
	int n;
	std::cin >> n;
	std::string s;
	while(n--, std::cin >> s){
		int pos = 0;
		while(pos = s.find("-", pos), pos != std::string::npos){
			s.replace(pos, 1, "");
		}

		std::map<char, char> m, rm;
		for(int i=1;i<s.size();i+=2){
			if(s[i] == '>')
				m[s[i+1]] = s[i-1], rm[s[i-1]] = s[i+1];
			else
				m[s[i-1]] = s[i+1], rm[s[i+1]] = s[i-1];
		}

		char end = (*m.begin()).first;
		std::cout << end << std::endl;
		while(m[end] != 0){
			end = m[end];
		}
		//whileI¹_ÅendÍstartÆÈé

		while(rm[end] != 0){
			std::cout << end;
			end = rm[end];
		}
		std::cout << end << '\n';
	}
}