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<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int n; cin >> n;
	rep(i, 0, n) {
		string s; cin >> s;
		bool b[256] = {};
		string ans ="";
		ans += s[0];
		b[s[0]] = true;
		for (int i = 1; i < s.size(); i += 3) {
			if (b[s[i + 2]])continue;
			b[s[i + 2]] = true;
			if (s[i] == '<') {
				ans = s[i + 2] + ans;
			}
			else {
				ans = ans + s[i + 2];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
string str,in;
char t[200];
int I;
int l,r,pos;
int main(){
  cin>>I;
  while(I--){
    cin>>str;
    l=100;
    r=100;
    t[100]=str[0];
    pos=100;

    for(int i=1;i<(int)str.size();i+=3){
      in=str.substr(i,3);

      if(in[0]=='<'){
	pos--;
	t[pos]=in[2];
	l=min(l,pos);
      }else{
	pos++;
	t[pos]=in[2];
	r=max(r,pos);
      }

    }
    
    for(int i=l;i<=r;i++){
      cout<<t[i];
    }
    cout<<endl;
    
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<char,int> P;

class mycmp{
public:
	bool operator() (const P p1,const P p2){
		return p1.second < p2.second;
	}
};

int main(){

	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		for(int i=0;i<n;i++){
			string str;
			cin >> str;

			vector<P> order;
			map<char,int> data;		
			set<char> alpha;

			for(int j=0;j<str.size();j++){
				if(isalpha(str[j])){
					alpha.insert(str[j]);
				}
			}

			int j=0;
			for(set<char>::iterator it = alpha.begin(); it != alpha.end(); it++){
				data[*it]=j++;
			}

			for(int k=0;k<alpha.size();k++){
				for(int j=0;j+3<str.size();j+=3){
					string tmp = str.substr(j,4);
					if(tmp.substr(1,2)=="<-"){
						if(data[tmp[0]] < data[tmp[3]]){
							swap(data[tmp[0]],data[tmp[3]]);
						}
					}
					else if(tmp.substr(1,2)=="->"){
						if(data[tmp[0]] > data[tmp[3]]){
							swap(data[tmp[0]],data[tmp[3]]);
						}
					}
				}
			}

			for(map<char,int>::iterator it = data.begin(); it != data.end();it++){
				order.push_back(P(it->first,it->second));
			}

			sort(order.begin(),order.end(),mycmp());

			for(vector<P>::iterator it = order.begin(); it != order.end();it++){
				cout << it->first;
			}

			cout << endl;
		}
	}
}

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

int main(void){
  int n;
  cin>>n;
  while(n--){
    char data[1024]={'0'};
    char indata[1024];
    int max = 512;
    int now = 512;
    int min = 512;
    cin>>indata;
    data[now]=indata[0];
    for(int i = 1; indata[i] != '\0'; i++){
      if(indata[i]=='>'){now++;max++;}
      else if(indata[i]=='<'){now--;min--;}
      else if(indata[i]=='-')continue;
      if(data[now]!='0')data[now]=indata[i];
    }
    for(int i = min; i <= max;i ++)
      cout<<data[i];
    cout<<endl;
  }
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std; 

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

const int INF = 1 << 24;

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

    while(n--){
        string in, res; cin >> in;
        res = in.at(0);

        COUNT(i, in.size() - 3){
            i += 2;
            string cur = in.substr(i, 1);

            if(~res.find(cur)) continue;
            switch(in.at(i - 2)){
                case '-':
                    res = res + cur;
                    break;
                case '<':
                    res = cur + res;
                    break;
            }
        }
        cout << res << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
string str,in;
char t[200];
int I;
int l,r,pos;
int main(){
  cin>>I;
  while(I--){
    cin>>str;
    l=100;
    r=100;
    t[100]=str[0];
    pos=100;

    for(int i=1;i<(int)str.size();i+=3){
      in=str.substr(i,3);

      if(in[0]=='<'){
	pos--;
	t[pos]=in[2];
	l=min(l,pos);
      }else{
	pos++;
	t[pos]=in[2];
	r=max(r,pos);
      }

    }
    
    for(int i=l;i<=r;i++){
      cout<<t[i];
    }
    cout<<endl;
    
  }
  return 0;
}

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

using namespace std;

int main(void)
{
	int n;
	string str;
	
	cin >> n;
	while (n--){
		cin >> str;
		
		deque <char> d;
		d.push_back(str[0]);
		bool done[30] = {false};
		done[str[0] - 'a'] = true;
		for (int i = 3; i < str.length(); i += 3){
			int now = str[i] - 'a';
			if (done[now]) {
				// cout << i << " vst" << endl;
				continue;
			}
			if (str[i - 1] == '>'){
				d.push_back(str[i]);
				done[now] = true;
			}
			else {
				d.push_front(str[i]);
				done[now] = true;
			}
		}
		for (int i = 0; i < d.size(); i++){
			cout << d[i];
		}
		cout << endl;
	}
	
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>
#include <utility>

typedef long long Int;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
#define REPS(a,i,n) for(int i = a ; i < n ; ++i)
using namespace std;

string ans;

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

	char buff;

	REP(i, n){
		string chain;

		cin >> chain;

		auto it = chain.begin();

		ans = *(it++);

		while (it != chain.end()){
			string tmp(it, it + 2);
			it += 2;

			buff = *(it++);

			if (tmp == "->"){
				if (ans.find(buff) == string::npos)
					ans = ans + buff;
			}
			if (tmp == "<-"){
				if (ans.find(buff) == string::npos)
					ans = buff + ans;

			}

		}
		cout << ans << endl;
	}

	return 0;
}