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 forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
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 ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int &s = 0, const int &d = 0, const Weight &w = 0) : src(s), dst(d), weight(w) {}
};

using Edges = std::vector<Edge>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

class Graph {
  std::vector<Edges> g;
  using iterator = std::vector<Edges>::iterator;
  using const_iterator = std::vector<Edges>::const_iterator;

public:
  Graph(const int &size = 0) : g(size) {}
  int size() const { return g.size(); }
  const Edges &operator[](const int &i) const { return g[i]; }
  void addArc(const int &src, const int &dst, const Weight &w = 1) { g[src].emplace_back(src, dst, w); }
  void addEdge(const int &node1, const int &node2, const Weight &w = 1) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }
  iterator begin() { return g.begin(); }
  const_iterator begin() const { return g.begin(); }
  iterator end() { return g.end(); }
  const_iterator end() const { return g.end(); }
};

std::vector<int> tsort(const Graph &g) {
  int n = g.size(), k = 0;
  std::vector<int> ord(n), in(n);
  for (auto &es : g) {
    for (auto &e : es) in[e.dst]++;
  }
  std::queue<int> q;
  rep(i, n) if (in[i] == 0) q.push(i);
  while (q.size()) {
    int v = q.front();
    q.pop();
    ord[k++] = v;
    for (auto &e : g[v])
      if (--in[e.dst] == 0) q.push(e.dst);
  }
  return *std::max_element(in.begin(), in.end()) == 0 ? ord : std::vector<int>();
}

main {
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    set<char> a;
    Graph g(26);
    rep(i, s.size() / 3) {
      a.insert(s[i * 3]);
      a.insert(s[i * 3 + 3]);
      if (s[i * 3 + 1] == '-') {
        g.addArc(s[i * 3] - 'a', s[i * 3 + 3] - 'a');
      } else {
        g.addArc(s[i * 3 + 3] - 'a', s[i * 3] - 'a');
      }
    }
    vi v = tsort(g);
    for (auto &x : v) {
      if (a.count(x + 'a')) cout << char(x + 'a');
    }
    cout << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    int n; cin >> n;
    int l;
    REP(n)
    {
        string s, ans, now = "0";
        cin >> s; l = (s.size())/3 + 1;
        //cout << "length = "<< l << endl;
        int pos = 0;
        now[0] = s[0];
        ans = now;
        rep(j,l - 1)
        {
            if(s[j*3+2] == '>') pos++;
            else pos--;
            now[0] = s[j*3 + 3];

            if(pos < 0){ ans = now + ans; pos++;}
            else if(pos == ans.size()){ ans = ans + now;}

        }
        cout << ans << endl;
    }

    return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

struct Info{
	char ch;
	int id;
};

int main(){

	int n,id;
	Info table[26];
	char buf[1100];

	scanf("%d",&n);

	for(int i=0; i < n; i++){
		for(int k=0; k < 26; k++){
			table[k].ch = 97 + k;
			table[k].id = 100;
		}

		id = 27;
		scanf("%s",buf);

		for(int k=0; buf[k] != '\0';k++){
			if(buf[k] >= 97 && buf[k] <= 122){
				if(table[buf[k]-97].id == 100){
					table[buf[k]-97].id = id;
				}
			}else{
				if(buf[k] == '>'){
					id++;
				}else if(buf[k] == '<'){
					id--;
				}
			}
		}

		for(int k=1; k <= 25; k++){
			for(int p=25; p >= k; p--){
				if(table[p].id < table[p-1].id)swap(table[p],table[p-1]);
			}
		}

		for(int i=0; i < 26; i++){
			if(table[i].id != 100)printf("%c",table[i].ch);
		}
		printf("\n");

	}

    return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    int n;
    cin>>n;
    while(n--){
        string s;
        cin>>s;
        vector<bool> used(2000,false);
        deque<char> deq;
        
        bool f=false;
        int pos = 1000;
        for(int i=0;i<s.size();i+=3){
            if(used[pos]==false){
                if(f==false || used[pos+1]==true){
                    f=true;
                    deq.push_front(s[i]);
                }else{
                    deq.push_back(s[i]);
                }
                used[pos]=true;
            }
            if(i+1>=s.size())continue;
            assert(s[i+1]=='<' || s[i+2]=='>');
            if(s[i+1]=='<')pos--;
            else if(s[i+2]=='>')pos++;
        }
        for(auto e:deq)cout<<e;
        cout<<endl;
    }
}

C++: #include<iostream>
using namespace std;
void solve(string buf){
	string ans="";
	ans+=buf[0];
	int target=0;
	for(string::iterator it=buf.begin()+1;it!=buf.end();){
		//cout<<"ans:"<<ans<<endl;
		//cout<<*it<<endl;
		if(*it=='<'){
			it+=2;
			string tmp="";
			if(target-1<0){
				tmp+=*it;
				tmp+=ans;
				ans=tmp;
			}
			else{
				target--;
			}
			it++;
		}
		else if(*it=='-'){
			it+=2;
			if(target+1>=ans.size())ans+=*it;
			target++;
			it++;
		}
	}
	cout<<ans<<endl;

}
int main(){
	int d;
	
	string buf;
	cin>>d;
	for(int i=0;i<d;i++){
		cin>>buf;
		solve(buf);
	}
	return 0;
}