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++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
template <class _Tv> inline string join(_Tv &v,string sep=" "){
    ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()
#define EPS (1e-9)
#define DEQ(p1,p2) (abs((p1)-(p2)) < EPS)

#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,_Tv _c,bool _p=false){
    ITER(_c) _it=_c.begin();
    if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

string solve(string s){
    string ret;
    int i = 0;
    FOREACH(it,s){
        char code = *it;
        if(islower(code)){
            if(i == -1){
                ret = code + ret;
                i = 0;
            } else if((int)ret.length() <= i){
                ret += code;
            }
        }
        if(code == '>'){ i++; }
        if(code == '<'){ i--; }
    }
    return ret;    
}

int main(){
    int n;
    cin >> n;
    REP(i,n){
        string s;
        cin >> s;
        cout << solve(s) << endl;
    }
    return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	int N; cin >> N;
	while (N--) {
		string st; cin >> st;
		int a = 0;
		int now = 26;
		int from = now;
		vector<int>anss(54,-1);
		while (1) {
			if (anss[now] == -1) {
				anss[now] = st[a] - 'a';
			}
			if (a == st.size() - 1)break;
			else {
				if (st[a + 1] == '-') {
					now++;
				}
				else {
					now--;
				}
				from = min(from, now);
			}
			a += 3;
		}
		for (int i = from; i < anss.size(); ++i) {
			if (anss[i] == -1)break;
			else {
				cout << char(anss[i] + 'a');
			}

		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        deque<char> Q;
        Q.emplace_back(s[0]);
        int cur = 0;
        for (int i = 3; i < s.size(); i += 3) {
            if(s[i-2] == '-'){
                cur++;
                if(Q.size() <= cur) Q.emplace_back(s[i]);
            }else {
                cur--;
                if(cur < 0) Q.emplace_front(s[i]), cur++;
            }
        }
        for (auto &&i : Q) cout << i;
        puts("");
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <climits>
#include <cfloat>
#include <queue>
#include <stack>

using namespace std;


#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define INF  INT_MAX

typedef long long LL;
typedef pair<int,int> P;
typedef vector<int,int> vii;


int main(){
    int n;cin>>n;
    while(n--){
        string s;cin>>s;
        char ans[2000];
        rep(i,2000) ans[i]='0';
        int now=1000;
        int start=1000,last=1000;
        //cout << s.length() << endl;
        for(int i=0;i<s.length();i+=3){
            //cout << i << endl;
            if(s[i]=='\n') break;
            ans[now]=s[i];
            if(s[i+2]=='>'){
                now++;
                if(now>last){
                    last=now;
                }
            }else if(s[i+1]=='<'){
                now--;
                if(start>now){
                    start=now;
                }
            }
        }
        //cout << start << endl;
        //cout << last << endl;
        for(int i=start;i<=last;i++){
            cout << ans[i];
        }
        cout << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    while (N--) {
        string str;
        cin >> str;
        string ans;
        ans += str[0];
        int corsor = 0;
        for (int i = 1; i * 3 + 1 <= str.size(); i++) {
            auto pre = string(str.begin() + (i-1)*3+1, str.begin() + (i-1)*3+3);
            if (pre == "<-") corsor--;
            else corsor++;

            if (corsor < 0) corsor = 0, ans = str[i*3] + ans;
            if (corsor >= ans.size()) ans += str[i*3];

        }
        cout << ans << endl;
    }

    return 0;
}