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 <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--n >= 0){
        string s;
        cin >> s;
        int m = s.size();

        deque<char> train(1, s[0]);
        int j = 0;
        for(int i=1; i<m; i+=3){
            if(s[i] == '<'){
                -- j;
                if(j < 0){
                    train.push_front(s[i+2]);
                    ++ j;
                }
            }else{
                ++ j;
                if(j == train.size())
                    train.push_back(s[i+2]);
            }
        }

        cout << string(train.begin(), train.end()) << endl;
    }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;

#define rep(i, n) for(int i = 0; i < n; i++)

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

bool intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

int main(){
	char res[1000];
	int n, pos, ind;
	string s;
	cin >> n;
	rep(t, n){
		cin >> s;
		fill(res, res + 1000, '?');
		int sz = s.size();
		ind = 1;
		pos = 500;
		res[pos] = s[0];
		while(ind < sz){
			char a = s[ind+1];
			char b = s[ind+2];
			ind += 3;
			if(a == '>') pos++;
			else pos--;
			res[pos] = b;
		}
		rep(i, 1000) if(res[i] != '?') cout << res[i];
		cout << endl;
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int train[30];

int main() {
	int n=in();
	while(n--){
		string str;
		cin>>str;
		int i;
		for(i=0;i<30;i++)train[i]=-1000;
		int m=0;
		int k=0;
		for(i=0;i<str.size();i++){
			if(i%3==0){
				train[str[i]-'a']=k;
			}
			if(i%3==2){
				if(str[i]=='>')k++;
				else k--;
				chmin(m,k);
			}
		}
		while(1){
			for(i=0;i<30;i++){
				if(train[i]==m){
					cout<<(char)(i+'a');
					m++;
					break;
				}
			}
			if(i==30)break;
		}
		cout<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int n, cnt, min, max;
  char hoge[10000];
  cin >> n;
  cin.ignore();
  while(n--){
    cnt = 1000, min = 1000, max = 1000;
    string num;
    cin >> num;
    for(int i=0;i<num.size();i++){
      if(num[i] == '>') cnt++;
      else if(num[i] == '<') cnt--;
      else if(num[i] != '-') hoge[cnt] = num[i];
      if(min > cnt) min = cnt;
      else if(max < cnt) max = cnt;
    }
    for(int i = min ; i <= max; i++){
      cout << hoge[i];
    }
    cout << endl;
  }
}

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

void solve(string line){
    char buffer[2100];
    int p = 1025;
    int l = p, r = p;
    buffer[p] = line[0];
    for ( int i = 3; i < line.size(); i+=3 ){
        if ( line[i-1] == '>' ) p++;
        else p--;
        buffer[p] = line[i];
        l = min(l, p); r = max(r, p);
    }
    for ( int i = l; i <= r; i++ ) cout << buffer[i];
    cout << endl;
}

main(){
    int tcase; cin >> tcase;
    string line;
    for ( int i = 0; i < tcase; i++ ) { cin >> line; solve(line); }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
int main(){
  int T;
  string record;
  cin >> T;
  while(T--){
    cin >> record;
    map<int, char> train;
    int now = 0;
    for(int i = 0 ; i < record.size(); i+=3){
      train[now] = record[i];
      if(record[i+1] == '<') now--;
      else now++;
    }
    
    for(map<int, char>::iterator it = train.begin() ; it != train.end() ; it++){
      cout << it->second;
    }
    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[26][2];
  int now_train;

  cin>> n;
  while(n--){
    for(int i=0;i<26;i++) data[i][0]=data[i][1]=-1;
    char c;
    cin>> c;
    now_train=abs('a'-c);
    
    string s;
    int max=-1;
    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;
  }
}