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<list>
#include<string>
using namespace std;

int main()
{
	int n, i;
	string s;
	list<char> l;
	list<char>::iterator it;
	cin>>n;
	while (getline(cin,s)) {
		l.clear();
		i = 0;
		l.push_back(s[0]);
		it = l.begin();
		while (++i<s.size()) {
			if (s[i++]=='<') {
				if (*(--it)++ != s[++i]) l.insert(it,s[i]);
				it--;
			} else if (s[i]=='>') {
				if (*(++it) != s[++i]) {
					l.insert(it,s[i]);
					it--;
				}
			}
		}
		for (it = l.begin(); it != l.end(); it++) cout<<*it;
		cout<<endl;
	}
	return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  string gomi;
  cin.ignore();
  while (n--) {
    string s;
    getline(cin, s);
    vc a;
    vs b;
    rep(i, s.size() / 3) {
      a.pb(s.substr(i * 3, 1)[0]);
      b.pb(s.substr(i * 3 + 1, 2));
    }
    a.pb(s.back());
    vi t(26, -1), f(26);
    loop(i, 1, a.size()) {
      if (b[i - 1] == "->") {
        t[a[i - 1] - 'a']                              = a[i] - 'a';
        if (f[a[i - 1] - 'a'] != -1) f[a[i - 1] - 'a'] = 1;
        f[a[i] - 'a']                                  = -1;
      } else {
        t[a[i] - 'a']                          = a[i - 1] - 'a';
        if (f[a[i] - 'a'] != -1) f[a[i] - 'a'] = 1;
        f[a[i - 1] - 'a']                      = -1;
      }
    }
    // for (int i = distance(f.begin(), find(all(f), 1)); i != -1; i = t[i]) {
    //   cout << char(i + 'a');
    // }
    cout << endl;
  }
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 
 using namespace std;

 int main()
 {
   int n;
   cin>>n;
   while(n--)
   {
     string s;
     int alpha[26]={0};
     deque<char> mm;
     deque<char>::iterator iter;
     cin>>s;
     mm.push_back(s[0]);
     alpha[s[0]-'a']++;
     for(int i=0;(i+3)<s.length();i=i+3)
     {
       if(s[i+1]=='-'&&s[i+2]=='>')
       {
         if(!alpha[s[i+3]-'a']) mm.push_back(s[i+3]);
         alpha[s[i+3]-'a']++;                                
       }
       else
       {
         if(!alpha[s[i+3]-'a']) mm.push_front(s[i+3]);
         alpha[s[i+3]-'a']++;     
       }        
     }          
     for(iter=mm.begin();iter!=mm.end();++iter)
     {
       cout<<(*iter);                                        
     }
     cout<<endl;
   } 
   //while(1);
   return 0;
 }

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

// infty
#define ULLINF (ULLONG_MAX)
#define LLINF  (LLONG_MAX)
#define IINF   (INT_MAX)
#define INF    (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();it++)

// rep
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// pair util
#define FST first
#define SND second

// range validator
#define CK(n,a,b) (a<=n && n<b)

// conversion
template<class T> inline string toStr(T a) { ostringstream oss_; oss_ << a; return oss_.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

int const dx[] = {-1,0,1,0,-1,1,1,-1};
int const dy[] = {0,-1,0,1,-1,-1,1,1};

//////////////////////////////////////////////////////////////


int main() {
  
  int Tc; cin >> Tc;
  while(Tc --) {
    list<char> lst;
    
    string s; cin >> s;
    int const N = s.size();
    
    lst.push_back(s[0]);
    for(int i=3; i<N; i+=3) {
      if(s[i-1] == '>') {
	list<char>::iterator it = find(ALL(lst), s[i-3]);
	advance(it, 1);
	if(s[i] != *it) lst.insert(it, s[i]);
      }
      else {
	list<char>::iterator it = find(ALL(lst), s[i-3]);
	if(it != lst.begin()) advance(it, -1);
	if(s[i] != *it) lst.insert(it, s[i]);
      }
    }

    EACH(it, lst) {cout << *it;}cout << endl;
  }
  
  return 0;
}

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


string solve(string in){
  string ans="";
  ans+=in[0];
  int pos=0;
  string op;
  char c;
  for(int i=1;i<in.size();){
    op=in.substr(i,2);
    c=in[i+2];
    i+=3;
    if(op=="->"){
      if(pos==ans.size()-1){
        ans=ans+c;
	pos++;
      }else{
        pos++;
      }
    }else{
      if(pos==0){
        ans=c+ans;
      }else{
        pos--;
      }
    }
  }
  return ans;
}

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