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>
#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]={};
		string S;
		cin>>S;
		for(int i=0;i<S.size();i++){
			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(e[i].size()>0) dfs(i,e,used);
		puts("");
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)
typedef long long ll;

using namespace std;

int main(void){

int n;
string s;

	while(cin >> n){
		if(cin.eof()) break;
		rep(i,n){
			cin >> s;
			int dt;
			string ans="";
			rep(j,s.size()){
				if(s[j] >= 'a' && s[j] <= 'z' ){
					if(ans=="") ans = s[j];
					bool fn=true;
					rep(k, ans.size()) if(s[j]==ans[k]) fn=false;
					if(fn && dt<0 ) ans = s[j] + ans;
					if(fn && dt>0 ) ans = ans  + s[j];

				}
				if(s[j] >= '<') dt=-1;
				if(s[j] >= '>') dt= 1;

			}
		cout << ans << endl;
		}
	}
	return 0;
	
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	int tc;cin>>tc;
	while(tc--){
		string s;
		cin>>s;
		deque<char> res;
		int pos=0;
		res.push_back(s[0]);
		for(int i=0;i<s.size();i+=3){
			if(s[i+1]=='<')
				pos--;
			else
				pos++;
			if(pos==-1){
				pos=0;
				res.push_front(s[i+3]);
			}
			else if(pos==res.size())
				res.push_back(s[i+3]);
		}
		rep(i,res.size())
			cout<<res[i]<<(i==res.size()-1?"\n":"");
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
char T[2000000]; int length = 1000000, n; string S;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int i = 0; i < 2000000; i++) {
			T[i] == ' ';
		}
		length = 1000000;
		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 < 2000000; i++) {
			if (T[i] != ' ') {
				cout << T[i];
			}
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<int, string> p;
int main() {
  int n;
  string str;
  scanf("%d\n",&n);

  for(int i=0;i<n;i++) {
    getline(cin,str);

    int pos = 27;
    vector<p> car;
    car.clear();
    for(unsigned int i=0;i<str.size();i+=3) {
      p  temp;
      temp.second=str.substr(i,1);
      temp.first = pos;
      car.push_back(temp);
      if(i==str.size()-1) break;
      if(str.substr(i+2,1) == ">") {
        pos++;
      }
      else {
        pos--;
      }
    }

    sort(car.begin(),car.end());
    if(car.size()!=0) {
      cout << car[0].second;
    }
    for(unsigned int i=1;i<car.size();i++) {
      if(car[i].second != car[i-1].second) {
        cout << car[i].second;
      }
    }
    cout << endl;
  }

}

C++: #include<cstdio>
#include<cstring>
#include<cstring>
using namespace std;
int main(){
	
	int n;
	scanf("%d",&n);
	
	for(int q = 0;q < n; q++){
		
		char str[1000] = {0};
		scanf("%s",str);
		
		char ans[1000] = {0};
		
		ans[0] = str[0];
		
		bool check[1280] = {0};
		
		check[str[0]] = 1;
		
		int x = 1;
		for(int i = 3; i < strlen(str); i+=3){
			
			if(check[str[i]] == 1)continue;
			check[str[i]] = 1;
			
			if(str[i-1] == '>'){
				ans[x] = str[i];
				x++;
			}
			else if(str[i-2] == '<'){
				for(int j = x;j > 0; j--)ans[j] = ans[j-1];
				ans[0] = str[i];
				x++;
			}
		}
		
		printf("%s\n",ans);
		
	}
	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int main(){
  string s;
  int n;
  while(cin>>n){
    while(n--){
      char train[52];
      for(int i=0;i<52;i++)train[i]='*';
      cin>>s;
      int pos=26;
      train[pos]=s[0];
      for(int i=3;i<s.size();i+=3){
        if(s[i-1]=='-')pos--;
        else pos++;
        train[pos]=s[i];
      }
      for(int i=0;i<52;i++){
        if(train[i]!='*'){
          while(1){
            cout<<train[i];
            i++;
            if(train[i]=='*')break;
          }
          cout<<endl;
          break;
        }
      }
    }
  }
}

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

using namespace std;

typedef pair<char, char> Train;

int main()
{
    int n;
    cin >> n;
    while(n--) {
        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;
    }
}