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 <iostream>
using namespace std;
 
typedef string::iterator S;
 
struct Node{
    char id;
    Node* prev;
    Node* next;
};
 
int main(){
    int n,i;
    cin>>n;
    while(n--){
        string expr;
        cin>>expr;
        Node vs[26];
        for(i=0;i<26;i++){
            vs[i].id=0;
            vs[i].prev=NULL;
            vs[i].next=NULL;
        }
        Node* vp = vs;
        Node* fr = vp+1;
        Node* head = vp;
        S s = expr.begin();
        while( true ){
            vp->id = *s;
            s++;
            if( s == expr.end() ) break;
            if( *s == '-' ){
                if( vp->next == NULL ){
                    vp->next = fr;
                    (vp->next)->prev = vp;
                    fr++;
                }
                vp = vp->next;
            }else{
                if( vp->prev == NULL ){
                    vp->prev = fr;
                    (vp->prev)->next = vp;
                    fr++;
                    head = vp->prev;
                }
                vp = vp->prev;
            }
            s += 2;
        }
        while( head ){
            cout << head->id;
            head = head->next;
        }
        cout << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
char T[1000000]; int length = 500000, n; string S;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int i = 0; i < 1000000; i++) {
			T[i] == ' ';
		}
		length = 500000;
		cin >> S;
		for (int i = 0; i <= S.size() / 3; i++) {
			T[length] = S[i * 3];
			if (S.size() != i) {
				if (S[i * 3 + 1] == '-') {
					length++;
				}
				else {
					length--;
				}
			}
		}
		for (int i = 0; i < 1000000; i++) {
			if (T[i] != ' ') {
				cout << T[i];
			}
		}
		cout << endl;
	}
}

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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){

  int n;
  int data[1000][2];
  int now_train;

  cin>> n;
  while(n--){
    for(int i=0;i<30;i++) data[i][0]=data[i][1]=-1;
    char c;
    cin>> c;
    now_train=abs('a'-c);
    
    string s;
    cin>> s;
    for(int i=0;i<s.size();i+=3){
      if(s[i]=='-'){
	data[now_train][1]=abs('a'-s[i+2]);
	data[abs('a'-s[i+2])][0]=now_train;
      }
      else{
	data[now_train][0]=abs('a'-s[i+2]);
	data[abs('a'-s[i+2])][1]=now_train;
      }
      now_train=abs('a'-s[i+2]);
    }
    
    string ans;
    int left,right;
    for(int i=0;i<26;i++){
      if(data[i][0]==-1 && data[i][1]!=-1){
	left=i;
	ans+='a'+left;
      }
      else if(data[i][1]==-1 && data[i][0]!=-1){
	right=i;
      }
    }
    while(left!=right){
      ans+='a'+data[left][1];
      left=data[left][1];
    }
    cout<< ans<< endl;
  }
}

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

int main()
{
  int n;
  while (cin >> n) {
    for (int dataset = 0; dataset < n; ++dataset) {
      string s;
      cin >> s;
      
      string ans = "";
      int index = 0;
      for (int i = 0; i < s.size(); i += 3) {
	if (index == (int)ans.size()) {
	  ans += s[i];
	} else if (index < 0) {
	  ans = s[i] + ans;
	  index = 0;
	}
	if (i+2 < s.size() && s[i+1] == '-' && s[i+2] == '>')
	  ++index;
	else if (i+2 < s.size())
	  --index;
      }
      cout << ans << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

void dfs(int n,vector<int> e[26],bool used[26]){
	if(used[n]) return;
	used[n] = true;
	for(int i=0;i<e[n].size();i++){
		dfs(e[n][i],e,used);
	}
	printf("%c",'a'+n);
}

int main(){
	int N;
	cin>>N;
	for(int ds=0;ds<N;ds++){
		vector<int> e[26];
		bool used[26]; fill_n(used,26,true);
		string S;
		cin>>S;
		for(int i=0;i<S.size();i++){
			if(isalpha(S[i])) used[S[i]-'a'] = false;
			int a = S[i-1]-'a', b = S[i+2]-'a';
			if(S[i]=='-' && S[i+1]=='>'){
				e[b].push_back(a);
			}
			else if(S[i]=='<' && S[i+1]=='-'){
				e[a].push_back(b);
			}
		}
		for(int i=0;i<26;i++) if(used[i]==false) dfs(i,e,used);
		puts("");
	}
	return 0;
}

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

using namespace std;

int main(){

  int n;

  cin >> n;

  vector<string> junkai(n);
  
  for(int i = 0;i < n;++i){
	cin >> junkai[i];

	string train;
	int point = 0;
	
	train = junkai[i][0];
	
	for(int j = 1;j < junkai[i].size();j+=3){
	  if(junkai[i][j] == '-' && junkai[i][j+1] == '>'){
		if(train[point + 1] == '\0'){
		  train += junkai[i][j+2];
		}
		point++;
	  }
		
	  else if(junkai[i][j] == '<' && junkai[i][j+1] == '-'){
		if(point == 0)
		  train = junkai[i][j+2] + train;
		else
		  point--;
	  }
	}
	cout << train << endl;
  }
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n;
	string s;
	cin>>n;
	rep(j,0,n){
		cin>>s;
		string ans="";
		ans=ans+s[0];
		rep(i,0,s.size()/3){
			if(ans.find(s[3*i+3])!=string::npos) continue;
			if(s[3*i+2]=='>'){
				ans=ans+s[3*i+3];
			}else{
				ans=s[3*i+3]+ans;
			}
		}
		cout<<ans<<endl;
	}
}

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

int main() {
    int n;
    cin >> n;
    cin.ignore();
    while (n--) {
        string line;
        getline(cin, line);
        string trainCars = "";
        trainCars += line[0];
        line.erase(0, 1);
        int i = 0;
        while (line.empty() == false) {
            if (line.substr(0, 2) == "->") {
                i++;
            } else {
                i--;
            }
            line.erase(0, 2);
            if (i == -1) {
                trainCars.insert(0, 1, line[0]);
                i = 0;
            } else if (i == (int) trainCars.length()) {
                trainCars += line[0];
            }
            line.erase(0, 1);
        }
        cout << trainCars << endl;
    }
}

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

int main()
{
	int i;
	string s;
	list<char> l;
	list<char>::iterator it;
	getline(cin,s);
	while (getline(cin,s)) {
		l.clear();
		i = 0;
		l.push_back(s[0]);
		it = l.begin();
		while (++i<s.size()) {
			if (s[i++]=='<') {
				if (*(--it)++ != s[++i]) l.insert(it,s[i]);
				it--;
			} else if (s[i]=='>') {
				if (*(++it) != s[++i]) {
					l.insert(it,s[i]);
					it--;
				}
			}
		}
		for (it = l.begin(); it != l.end(); it++) cout<<*it;
		cout<<endl;
	}
	return 0;
}