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++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main() {
	int n;
	cin>>n;
	REP(i,n){
		string s ;
		cin >>s;
		list<char> l;
		l.push_back(s[0]);
		int p=0;
		for(int j=1;j<s.size();j+=3){
			char c=s[j+2];
			if(s[j]=='-'){
				p++;
				if(p>=l.size()){
					l.push_back(c);
				}
			}else{
				p--;
				if(p<0){
					l.push_front(c);
					p=0;
				}
			}
		}
		EACH(list<char>,it,l){
			cout<<(*it);
		}
		cout<<endl;
	}
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
vector<int>g[26];
vector<int>ans;
bool used[26];
void dfs(int pos){
    if(used[pos])return;
    used[pos]=true;
    for(int i=0;i<g[pos].size();i++){
        dfs(g[pos][i]);
    }
    ans.push_back(pos);
}
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        fill_n(g,26,vector<int>(0));
        fill_n(used,26,false);
        ans.clear();
        char str[1025];
        scanf("%s",str);
        if(strlen(str)==1){
            printf("%c\n",str[0]);
            continue;
        }
        for(int i=1;str[i];i+=3){
            int v1=str[i-1]-'a';
            int v2=str[i+2]-'a';
            if(str[i]=='-'){
                g[v1].push_back(v2);
            }
            else{
                g[v2].push_back(v1);
            }
        }
        for(int i=0;i<26;i++){
            sort(g[i].begin(),g[i].end());
            g[i].erase(unique(g[i].begin(),g[i].end()),g[i].end());
        }
        for(int i=0;i<26;i++)if(g[i].size())dfs(i);
        reverse(ans.begin(),ans.end());
        for(int i=0;i<ans.size();i++){
            printf("%c",ans[i]+'a');
        }
        puts("");
    }

    return 0;
}

C++: 
#include <iostream>
#include <map>
int main(){
	int n;
	std::cin >> n;
	std::string s;
	while(n--){
		std::cin >> s;

		if(s.size() == 1){
			std::cout << s << std::endl;
			continue;
		}

		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;
		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';
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  string s;
  cin >> n;
  getline(cin, s);
  for(int i = 0; i < n; i++) {
    getline(cin, s);
    vector<char> c;
    vector<int> a;

    for(int j = 0; j < s.size(); j++) {
      if(j%3 == 0) c.push_back(s[j]);
      if(j%3 == 1) {
	if(s.substr(j, 2) == "->") a.push_back(0);
	else a.push_back(1);
      }
    }

    string ans;
    ans += c[0];
    for(int j = 1; j < a.size(); j++) {
      int p;
      bool b = true;
      for(int k = 0; k < ans.size(); k++) {
	if(c[j] == ans[k]) {
	  b = false;
	}
	if(c[j-1] == ans[k]) {
	  p = k;
	}
      }
      if(!b) continue;
      
      string tmp1 = ans.substr(0,p+1-a[j]);
      string tmp2 = ans.substr(p+1-a[j]);
      ans = tmp1;
      ans += c[j];
      ans += tmp2;
    }
    cout << ans << endl;
  }
}

C++: #include <cstdio>
#include <list>
using namespace std;
int main(){
	typedef list<char> lc;
	int n;
	char c,d;
	for(scanf("%d ",&n);n--;scanf(" ")){
		lc ls;
		ls.push_back(getchar());
		lc::iterator it=ls.begin();
		for(;d=getchar(),d=='-'||d=='<';){
			getchar();
			c=getchar();
			if(d=='-'){
				if(++it==ls.end())it=ls.insert(it,c);
			}else{
				if(it==ls.begin())it=ls.insert(it,c);
				else --it;
			}
		}
		for(it=ls.begin();it!=ls.end();++it)putchar(*it);
		puts("");
	}
}

C++: #include <iostream>
#include <map>
#include <string>

using namespace std;

typedef pair<char, char> Train;

int main()
{
    int n;
    cin >> n;
    while(n-- > 0) {
        string str;
        cin >> str;
        map<char, Train> vt;
        char a, b;
        for (int i = 1; i < str.size(); i += 3) {
            a = str[i - 1]; b = str[i + 2];
            string op = str.substr(i, 2);
            if(vt.find(a) == vt.end()) {
                vt[a] = Train(' ', ' ');
            }

            if (vt.find(b) == vt.end()) {
                vt[b] = Train(' ', ' ');
            }

            if (op == "->") {
                vt[a].second = b;
                vt[b].first = a;
            } else {
                vt[b].second = a;
                vt[a].first = b;
            }
        }

        while (vt[a].first != ' ')
            a = vt[a].first;
        
        while (true) {
            cout << a;
            a = vt[a].second;
            if (vt[a].second == ' ') {
                cout << a;
                break;
            }
        }
        cout << endl;
    }
}

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

int main()
{
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		string c;
		cin >> c;
		int sum = 26, MAX = 0,MIN=1<<29;
		char train[52];
		for (int d = 0; d < c.length()/3+1; d++) {
			train[sum] = c[d*3];
			MAX = max(MAX, sum);
			MIN = min(MIN, sum);
			if (d<c.length()/3) {
				if (c[d*3+2] == '>')sum++;
				else sum--;
			}
		}
		for (int i = MIN; i <= MAX; i++) {
			cout << train[i];
		}
		cout << endl;
	}
}