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 <stdio.h>
#include <string.h>

int main(void)
{
	char vehi[1024][52 + 1];
	char *current;
	int n;
	char in[1025];
	
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++){
		int j;
		
		scanf("%s", in);
		current = vehi[i] + 26;
		memset(vehi[i], 0, 53 * sizeof(char));
		
		*current = in[0];
		j = 1;
		while (in[j] != '\0'){
			switch (in[j]){
				case '<':		 current--; break;
				case '>':		 current++; break;
				case '-':					break;
				default:  *current = in[j]; break;
			}
			j++;
		}
	}
	
	for (int i = 0; i < n; i++){
		int j;
		j = 0;
		while (vehi[i][j] == 0){
			j++;
		}
		while (vehi[i][j] != 0){
			printf("%c", vehi[i][j]);
			j++;
		}
		puts("");
	}
	
	return (0);
}

C++: #include <stdio.h>
#include <math.h>

#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 10000000;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;


/** Problem0130 : Train **/
int main()
{
	string s; int n;
	cin>>n;
	rep(k, n) {
		cin>>s;
		int d=0, i=1;
		string ans;
		bool ahead;
		string t;
		
		ans = s[0]; t = s[0];
		for (; i<s.size(); i++) {
			if (s[i]=='>') {
				ahead=true;
			} else if (s[i]=='<') {
				ahead=false;
				i++;
			} else if ('a'<= s[i] && s[i] <= 'z') {
				int pos = (int)ans.find(t, 0);
				if (string::npos == ans.find(s[i], 0)) {
					if (ahead) {
						ans.insert(pos+1, 1, s[i]);
					} else {
						ans.insert(pos, 1, s[i]);
					}
				}
				t=s[i];
			}
		}
		cout << ans << endl;
	}
}

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

int main(){
	int n;cin >> n;
	string s;
	while(n--){
		deque<char> d;
		cin >> s;
		int p = 0;
		d.push_back(s[0]);
		for(int i = 1;i < s.size();i += 3){
			if(s[i] == '<'){
				if(!p)d.push_front(s[i+2]);
				else p--;
			}else{
				if(p == d.size()-1)d.push_back(s[i+2]);
				p++;
			}
		}
		for(int i = 0;i < d.size();i++)cout << d[i];
		cout << endl;
	}
	return 0;
}

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

bool find(string a, char c) {
  for(int i = 0; i < a.length(); i++) {
    if(a[i] == c) return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    string str;
    cin >> str;

    string ans = str.substr(0,1);
    for(int i = 1; i < (str.length()+2)/3; i++) {
      if(find(ans, str[i*3])) continue;
      if(str[i*3-2] == '-' && str[i*3-1] == '>') {
	ans += str[i*3];
      } else if(str[i*3-2] == '<' && str[i*3-1] == '-') {
	ans = str.substr(i*3,1) + ans;
      }
    }

    cout << ans << endl;
  }
  return 0;
}

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

int main()
{
    int n;
    string s;
    cin >> n;
    getline(cin, s);
    for(int i = 0; i < n; i++)
    {
        string ans;
        string in_str;
        bool is_appeared[26] = {};
        std::getline(cin, in_str);
        ans.push_back(in_str[0]);
        is_appeared[in_str[0] - 'a'] = true;
        for(int j = 1; j < in_str.length() - 2; j++)
        {
            if(is_appeared[in_str[j + 2] - 'a'])
            {
                continue;
            }
            else
            {
                is_appeared[in_str[j + 2] - 'a'] = true;
            }

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

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
char buf[1025], res[128], mem[26], *p;
int n, l, r, h, t;
int main()
{
    n = atoi(fgets(buf, 1025, stdin));
    while (n--) {
        memset(res, 0, sizeof(res));
        memset(mem, 0, sizeof(mem));
        fgets(buf, 1025, stdin);
        p = &buf[strlen(buf)-1];
        if (*p == '\n') *p = '\0';

        h = t = 0;
        l = sizeof(res) / 2 - 1;
        r = sizeof(res) / 2 + 1;
        res[sizeof(res) / 2] = buf[0];
        mem[buf[0]-'a'] = 1;
        REP(i, 1, strlen(buf)) {
            if (buf[i] == '-') continue;
            else if (buf[i] == '<') { h = 1; t = 0; }
            else if (buf[i] == '>') { h = 0; t = 1; }
            else {
                if (mem[buf[i]-'a']) continue;
                mem[buf[i]-'a'] = 1;
                if (h) res[l--] = buf[i];
                else if (t) res[r++] = buf[i];
            }
        }
        rep(i, sizeof(res)) if (res[i] > 0) putchar(res[i]);
        puts("");
    }
    return 0;
}