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 <cstdio>
#include <iostream>
using namespace std;
int main() {
    int t; scanf("%d",&t);
    for (int ix=0; ix<t; ix++) {
        string str; cin>>str;
        string res="", temp="";
        res+=str[0];
        int pos=0;
        for (int i=1; i<str.length(); i++) {
            if (str[i]!='-'&&str[i]!='>'&&str[i]!='<') {
                if (temp=="->") {
                    pos++;
                    if (res.length()==pos) res+=str[i];
                    else if (res[pos]!=str[i]) {
                        res+='x';
                        for (int j=res.length()-1; j>pos; j--) {
                            res[j]=res[j-1];
                        }
                        res[pos]=str[i];
                    }
                } else {
                    pos--;
                    if (pos==-1) {
                        res=str[i]+res;
                        pos=0;
                    } else if (res[pos]!=str[i]) {
                        res='x'+res;
                        for (int j=0; j<pos; j++) {
                            res[j]=res[j+1];
                        }
                        res[pos]=str[i];
                    }
                }
                temp="";
            } else temp+=str[i];
        }
        cout<<res<<endl;
    }
}

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

int main(){

  int n, len_str, len_vc, pos;
  string str;
  vector<char> vc;

  cin >> n;
  
  for(int i=0; i<n; i++){
    cin >> str;
    len_str = str.length();
    vc.clear();
    vc.push_back(str[0]);
    len_vc = 1;
    pos = 0;
  
    for(int j=1; j<len_str; j+=3){
      if(str[j] == '<'){
        if(pos != 0) pos--;
        else{
          vc.insert(vc.begin(), str[j+2]);
          len_vc++;
        }
      }
      else{
        if(pos != len_vc - 1) pos++;
        else{
          vc.push_back(str[j+2]);
          len_vc++;
          pos++;
        }
      }
    }
  
    for(int j=0; j<len_vc; j++){
      cout << vc[j];
    }
    cout << endl;
 
  }

  return 0;

}

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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n; cin >> n;
  while(n--) {
    string s; cin >> s;
    deque<char> dq;
    set<char> st;
    dq.push_front(s[0]);
    st.insert(s[0]);
    reps(i, 3, s.size()) {
      if(!st.count(s[i])) {
	if(s[i-1] == '>') dq.push_back(s[i]);
	else dq.push_front(s[i]);
	st.insert(s[i]);
      }
      i+=2;
    }
    while(!dq.empty()) {
      cout << dq.front(); dq.pop_front();
    }
    cout << endl;
  }
  
  return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define R 1
#define L -1


int main(){
	int n;
	cin>>n;
	rep(loop,n){
		string s;
		cin>>s;
		int now = 0;
		string ans = string(1,s[0]);

		for(int i=1;i<s.size();i+=3){
			int alph = s[i+2];
			int dir = s[i+1]=='>'?R:L;

			now+=dir;
			if(dir == R){
				if(now == ans.size()){
					ans = ans+string(1,alph);
				}
			}else{
				if(now == -1){
					ans = string(1,alph)+ans;
					now = 0;
				}
			}
		}
		cout<<ans<<endl;
	}
}

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

int main() {
    int n;
    cin >> n;
    cin.ignore();
    for (int i=0; i<n; ++i) {
        string res(100, ' '), s;
        getline(cin, s);
        int k = 50;
        res[k] = s[0];
        for (int j=3; j<(int)s.size(); j+=3) {
            if (s[j-1] == '>') {
                k ++;
            } else {
                k --;
            }
            res[k] = s[j];
        }
        string res2 = "";
        for (int i=0; i<100; ++i) {
            if (res[i] != ' ') {
                res2 += res[i];
            }
        }
        cout << res2 << endl;
    }
    return 0;
}

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

using namespace std;

#define MAX 26

bool data[MAX][MAX];
bool used[MAX];
vector<char> ans;
set<int> st;

bool cyc(int now, int cnt){
  if(cnt == 1){
    return true;
  }
  set<int>::iterator it;
  for(it = st.begin() ; it != st.end() ; ++it){
    int next = (*it) - 'a';
    ans.push_back((char)(*it));
    if(data[now][next] && cyc(next, cnt-1)){
      return true;
    }
    ans.pop_back();
  }
  return false;
}

int main(){
  int n;
  string str;

  cin >> n;
  while(n--){
    memset(data,false,sizeof(data));
    st.clear();

    cin >> str;
    string tmp;
    for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == '-') continue;
      tmp += str[i];
    }
    str = tmp;
    st.insert(str[0]);
    for(int i = 2 ; i < str.size() ; i += 2){
      if(str[i-1] == '<'){
        data[str[i]-'a'][str[i-2]-'a'] = true;
      }else{
        data[str[i-2]-'a'][str[i]-'a'] = true;
      }
      if(!st.count(str[i])){
        st.insert(str[i]);
      }
    }

    int size = st.size();
    set<int>::iterator it;
    for(it = st.begin() ; it != st.end() ; ++it){
      ans.clear();
      memset(used,false,sizeof(used));
      ans.push_back((char)(*it));
   
      if(cyc((*it)-'a', size)){
        break;
      }
    }

    for(int i = 0 ; i < ans.size() ; i++){
      cout << ans[i];
    }
    cout << endl;
  }

  return 0;
}

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[256] = {};
        cin >> in_str;
         
        ans += in_str[0];
        is_checked[in_str[0]] = true;
        //cout << "debug: ascii " << in_str[0] - 'a' << " "
        //     << "in_str[j] = "  << in_str[0] << endl;
        for(int j = 1; j < in_str.size(); 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]])
            {
                continue;
            }

            is_checked[in_str[j + 2]] = 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;
}