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<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>

using namespace std;

void Solution()
{
    int n;
    
    cin>>n;
    
    for(int i = 0; i < n; i++)
    {
        string s, str;
        
        cin>>s;
        
        int p=0;
        
        for(int j = 0; j < (int)s.size(); j++)
        {
            if(s[j] == '>')
            {
                p++;
            }
            else if(s[j] == '<')
            {
                p--;
            }
            else if('a' <= s[j] && s[j] <= 'z')
            {
                if(p == -1)
                {
                    str = s[j] + str;
                    
                    p = 0;
                }
                else if(p == (int)str.size())
                {
                    str = str + s[j];
                }
            }
        }
        
        cout<<str<<"\n";
    }
}

int main()
{
    Solution();
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
int main(){
  int T;
  string record;
  cin >> T;
  while(T--){
    cin >> record;
    map<int, char> train;
    int now = 0;
    for(int i = 0 ; i < record.size(); i+=3){
      train[now] = record[i];
      if(record[i+1] == '<') now--;
      else now++;
    }
    
    for(map<int, char>::iterator it = train.begin() ; it != train.end() ; it++){
      cout << it->first  << it->second << ' ';
    }
    cout << endl;
  }
}

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

int main(){
    int n;
    cin >> n;
    for(int i=0; i < n; i++){
        string input;
        cin >> input;

        string ans = input.substr(0, 1);
        input = input.substr(1);
        int pointer = 0;
        while(input.size() != 0){
            if(input.substr(0, 2) == "->"){
                if(ans.size() > pointer+1) ans.replace(pointer+1, 1, input.substr(2, 1));
                else ans += input.substr(2, 1);
                pointer++;
            }
            else {
                if(pointer == 0) ans = input.substr(2, 1) + ans;
                else pointer--;
            }
            input = input.substr(3);
        }
        cout << ans << endl;
    }
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

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

const int INF = 100000000;
struct UF {
    vi e;
    UF(int n) : e(n, -1) {}
    bool same_set(int a, int b) { return find(a) == find(b); }
    int size(int x) { return -e[find(x)]; }
    int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }

    void join(int a, int b) {
        a = find(a), b = find(b);
        if(a == b) return;
        if(e[a] > e[b]) swap(a, b);
        e[a] += e[b]; e[b] = a;
    }
};
int main() {
    //cout << fixed << setprecision(15);

    int n; cin >> n;
    while(n--){

        string s; cin >> s;
        int len = sz(s);


        // -> push_back
        // <- push_front

        //

        int arr[1010];
        REP(i, 1010) arr[i] = -1;
        arr[500] = s[0]-'a';

        int idx = 500;
        for(int i=1; i<len; i+=3){
            if(s[i+1] == '>'){
                idx++;
                arr[idx] = s[i+2]-'a';
            }else{
                idx--;
                arr[idx] = s[i+2]-'a';
            }
        }

        string ans = "";
        for(int i=0; i<1010; ++i){
            if(arr[i]!=-1){
                ans += (char)('a'+arr[i]);
            }
        }
    cout << ans << endl;


    }
    return 0;
}