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>
#include <cstdlib>

using namespace std;

struct list {
	char c;
	struct list *front;
	struct list *back;
};

list *make_list(char c,list *f, list *b) {
	list* l = (list*)malloc(sizeof (list));
	l->c = c;
	l->front = f;
	l->back = b;
	return l;
}

int main() {
	int n;
	string b;
	cin >> n;
	for (int i = 0; i < n; i++) {
		list* train = (list*)malloc(sizeof (list));
		cin >> b;
		list** t;
		train->c = b[0];
		train->front = NULL;
		train->back = NULL;
		for (int j = 1; j < b.size(); j++) {
			if (b[j] == '-') {
			} else if (b[j] == '>') {
				if (train->back == NULL) {
					train->back = make_list(b[j+1], train, NULL);
				}
				train = train->back;
				j++;
			} else if (b[j] == '<') {
				if (train->front == NULL) {
					train->front = make_list(b[j+2], NULL, train);
				}
				train = train->front;
				j+=2;
			} 
		}
		while (train->front != NULL) {
			train = train->front;
		}
		while (train->back != NULL) {
			cout << train->c;
			train = train->back;
		}
		cout << train->c << 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 = 0, min = 0, max = 0;
    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 <list>
#include <cstring>
using namespace std;

int main(){
	int n,sw;
	bool f[30];
	string str;
	list<char> li;
	cin >> n;
	for(int i = 0;i < n;++i){
		sw = 0;
		memset(f,0,sizeof(f));
		li.clear();
		cin >> str;
		for(int j = 0;j < str.size();++j){
			if(str[j] == '<') sw = 0;
			else if(str[j] == '>') sw = 1;
			else if(str[j] != '-'){
				if(!f[(int)(str[j] - 'a')]){
					if(sw) li.push_back(str[j]);
					else li.push_front(str[j]);
				}
				f[(int)(str[j] - 'a')] = true;
			}
		}
		list<char>::iterator it = li.begin();
		while(it != li.end()){
			cout << *it;
			++it;
		}
		cout << endl;
	}
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int sz = s.size();
    string ans(1, s[0]);
    char used[26] = {};
    used[s[0] - 'a'] = true;
    for (int j = 0; j + 3 < sz; j += 3) {
      if (used[s[j + 3] - 'a']) continue;
      used[s[j + 3] - 'a'] = true;
      if (s.substr(j + 1, 2) == "->") ans = ans + s[j + 3];
      else ans = s[j + 3] + ans;
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<deque>
#include<string>
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,n) loop(i,0,n)

using namespace std;

int main(){
    deque<char> d;
    string s;
    int n; cin >> n;
    rep(i,n){
        cin >> s;
        int p = 0, max = 0, min = 0;
        d.clear();
        d.push_back(s[0]);
        rep(k, s.size())if (k){
            if (s[k] == '-') p++;
            else p--;
            k += 2;
            if (p>max){
                d.push_back(s[k]);
                max = p;
            }
            else if (p<min){
                d.push_front(s[k]);
                min = p;
            }
        }

        rep(i, d.size()){
            cout << d[i];
        }
        cout << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




int main() {
	string s, t;
	int n;
	cin >> n;
	rep(i, n) {
		cin >> s;
		vi v(26, 0);
		t = "";
		//cout << s.size() << endl;
		for (int i = 0; i < s.size(); i += 3) {
			if (i == 0) {
				t += s[0];
				v[s[0] - 'a'] = 1;
			}
			else {
				if (v[s[i] - 'a'] == 0) {
					if (s[i - 1] == '>') {
						t += s[i];
						//cout << " " << t << endl;
					}
					if (s[i - 1] == '-') {
						t = s[i] + t;
						//cout << " " << t << endl;
					}
					v[s[i] - 'a'] = 1;
				}
			}
		}
		cout << t << endl;
	}
}

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

int main(){
  char tid[60],buf[1030];
  int tidi,n,bi;

  cin >> n;

  for (int i=0;i<n;i++){
    for (int j=0;j<60;j++)tid[j]=0;
    bi=0;
    tidi=30;
    cin >> buf;
    tid[tidi]=buf[bi++];
    while (buf[bi]!='\0'){
      if (buf[bi]=='-')tidi++;
      else tidi--;
      bi+=2;
      tid[tidi]=buf[bi];
      bi++;
    }
    for (tidi=0;tid[tidi]=='\0';tidi++);
    cout << &tid[tidi]<< endl;
  }
  return 0;
}

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[30][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;
    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;
  }
}