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 <string>
using namespace std;

int main()
{
    int n;
    cin >> n;

    for(int i = 0; i < n; i++)
    {
        string in_str;
        string ans;
        bool is_checked[200] = {};
        cin >> in_str;
         
        ans += in_str[0];
        is_checked[in_str[0] - 'a'] = true;
        //cout << "debug: ascii " << in_str[0] - 'a' << " "
        //     << "in_str[j] = "  << in_str[0] << endl;
        for(int j = 1; j < in_str.size() - 2; j = j + 3)
        {
            //cout << "debug: ascii " << in_str[j + 2] - 'a' << " "
            //     << "in_str[j + 2] = "  << in_str[j + 2] << endl;
            if(is_checked[in_str[j + 2] - 'a'])
            {
                continue;
            }

            is_checked[in_str[j + 2] - 'a'] = true;

            if(in_str[j] == '-' && in_str[j + 1] == '>')
            {
                ans = ans + in_str[j + 2];
            }
            else if(in_str[j] == '<' && in_str[j + 1] == '-')
            {
                ans = in_str[j + 2] + ans;
            }
            else
            {
                /* Nop */
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
   int n;
   cin >>n;
 string s;
   cin >>s;
   for(int i=0;i<n;i++){
   int array[60];
    array[30]=s[0];
    int t=30;
   for(int i=0;i<s.length();i++){
   if(){
       t +=  1;
       array[t]=s[3*i];
   }else{
       t -= 1;
       array[t]=s[3*i];
   }
   }
   for(int i=0;i<60;i++){
       if(array[i]!=0){
           cout <<array[i];
       }
   }  
   cout <<endl;










   }
return 0;
}

C++: /*
	0130:Train
*/
#include	<iostream>
#include	<vector>
#include	<string>
#include	<utility>
#include	<algorithm>

using namespace std;

typedef vector< pair<int, char> > VpIC;

string solve(string hoge);

int main(void) {
	int data;
	
	cin >> data;
	for(int i = 0; i < data; i++) {
		string aaa;
		
		cin >> aaa;
		cout << solve(aaa) << endl;
	}
	
	return 0;
}

string solve(string hoge) {
	string::iterator it = hoge.begin();
	string ans;
	int rank = 0, count = 0;
	VpIC list;
	int piyo[26] = { 0 };
	
	while( it != hoge.end() ) {
		if(*it == '-') {
			rank--;
			it++;	it++;
		} else if(*it == '<') {
			rank++;
			it++;	it++;
		} else {
			if( piyo[*it - 'a'] == 0) {
				list.push_back( pair<int, char>(rank, *it) );
				piyo[*it - 'a'] = 1;
				count++;
			}
			it++;
		}
	}
	sort(list.begin(), list.end());
	for(int i = count-1; i >= 0; i--) {
		ans += list[i].second;
	}
	
	return ans;
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        vector<int> post(30,-1),pre(30);
        string s;
        cin >> s;
        if(s.size() < 3){
            cout << s << endl;
        }else{
            for(int j = 3; j < s.size(); j += 3){
                int now = s[j] - 'a';
                int bef = s[j-3] - 'a';
                if(s[j-2] == '<')swap(now,bef);
                post[bef] = now;
                pre[now]++;
            }
            for(int j = 0; j < 30; j++){
                if(pre[j] == 0 && post[j] != -1){
                    int now = j;
                    cout << char('a' + now);
                    while(post[now] != -1){
                        now = post[now];
                        cout << char('a' + now);
                    }
                    cout << endl;
                }
            }
        }
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second


main(){
  int n;
  cin>>n;
  while(n--){
    string in,ans;
    cin>>in;
    int pos=0;
    rep(i,in.size()){
      if(isalpha(in[i])){
        ans+=in[i];
        pos=0;
      }else if(in[i]=='-')continue;
      else if(in[i]=='<'){
        i+=2;
        pos--;
        if(pos<0)ans=in[i]+ans,pos=0;
      }else{
        i++;
        pos++;
        if(pos>=ans.size())ans+=in[i];
      }
    }
    cout<<ans<<endl;
  }
}

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=3;i<s.size();i+=3){
			if(s[i-1]=='>')
				pos++;
			else
				pos--;
			if(pos==-1){
				pos=0;
				res.push_front(s[i]);
			}
			else if(pos==res.size())
				res.push_back(s[i]);
		}
		rep(i,res.size())
			cout<<res[i]<<(i==res.size()-1?"\n":"");
	}
	
	return 0;
}