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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string solve(string str) {
  int it = 0;
  deque<char> res;
  res.push_back(str[0]);
  for (int i = 1; i < str.size(); i += 3) {
    bool isFront = true;
    if (str[i] != '-') isFront = false;
    if (isFront) {
      ++it;
      if (it >= res.size()) {
	res.push_back(str[i+2]);
      }
    }
    else {
      --it;
      if (it < 0) {
	++it;
	res.push_front(str[i+2]);
      }
    }
    //for (int i = 0; i < res.size(); ++i) cout << res[i];
    //cout << ", " << it << endl;
  }
  string sres = "";
  for (int i = 0; i < res.size(); ++i) {
    sres += res[i];
  }
  return sres;
}

int n;
int main() {
  while (cin >> n) {
    string str;
    for (int i = 0; i < n; ++i) {
      cin >> str;
      cout << solve(str) << endl;
    }
  }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	REP(i,N){
		string S=in<string>();
		vector<char> T(60,'\0');
		int pos=30;
		int M=S.size();
		for(int j=0;j<M;){
			if(S[j]=='-'){
				pos++;
				j+=2;
			}
			else if(S[j]=='<'){
				pos--;
				j+=2;
			}
			else{
				T[pos]=S[j];
				j++;
			}
		}
		for(auto& x:T){
			if(x!='\0') cout<<x;
		}
		out();
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
char T[1000000]; int length = 500000, n; string S;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int i = 0; i < 1000000; i++) {
			T[i] = ' ';
		}
		length = 500000;
		cin >> S;
		for (int i = 0; i <= S.size() / 3; i++) {
			T[length] = S[i * 3];
			if (S.size() != i) {
				if (S[i * 3 + 1] == '-') {
					length++;
				}
				else {
					length--;
				}
			}
		}
		for (int i = 0; i < 1000000; i++) {
			if (T[i] != ' ') {
				cout << T[i];
			}
		}
		cout << endl;
	}
}

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

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  int n; cin >> n;
  while(n --> 0){
    string ans;
    int apos = 0;
    int pos = 0;
    string str;
    cin >> str;
    ans = str[0];
    pos+=2;
    while(pos < str.size()){
      //printf("str[pos]=%c\n",str[pos]);
      if(str[pos] == '-'){
        apos--;
      }else{
        apos++;
      }
      pos++;
      //printf("%s (apos = %d)\n",ans.c_str(),apos);
      if(apos == -1){
        apos = 0;
        ans = str[pos] + ans;
      }else if(apos == ans.size()){
        ans = ans + str[pos];
      }else{
      }
      pos += 2;
    }
    cout << ans << 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 1;
    }
    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 1;
	}
	ans.pop_back();
    }
    return 0;
}
 
int main()
{
    int n;
    string str;
 
    cin >> n;
    while (n--) {
	memset(data, 0, sizeof(data));
	st.clear();
 
	cin >> str;
	string tmp;
	for (int i = 0; i < (int)str.size(); i++) {
	    if (str[i] == '-') continue;
	    tmp += str[i];
	}
	str = tmp;
	st.insert(str[0]);
	for (int i = 2; i < (int)str.size(); i += 2) {
	    if (str[i-1] == '<') {
		data[str[i]-'a'][str[i-2]-'a'] = 1;
	    } else {
		data[str[i-2]-'a'][str[i]-'a'] = 1;
	    }
	    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, 0, sizeof(used));
	    ans.push_back((char)(*it));
    
	    if (cyc((*it)-'a', size)) {
		break;
	    }
	}
	for (int i = 0; i < (int)ans.size(); i++) {
	    cout << ans[i];
	}
	cout << endl;
    }
    return 0;
}