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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P,P> PP;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int n;
    cin >> n;
    REP(i,n){
        string s;
        cin >> s;
        deque<char> train;
        train.push_back(s[0]);
        int pos = 0, l = 0, r = 0;
        for(int j=1;j*3<=int(s.size());j++){
            if(s[j*3-1]=='>'){
                if(pos==r){
                    train.push_back(s[j*3]);
                    r++;
                }
                pos++;
            }
            else{
                if(pos==l){
                    train.push_front(s[j*3]);
                    l--;
                }
                pos--;
            }
        }
        for(auto c : train){
            cout << c;
        }
        cout << endl;
    }
    return 0;
}

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

int main(){
	int n;
	string str;
	list< char > lst;
	
	cin >> n;
	
	for(int i = 0; i < n; ++i){
		cin >> str;
		bool dir = false;
		lst.clear();
		
		for(int j = 0; j < str.length(); ++j){
			char ch = str[j];
			
			if(ch >= 'a' && ch <= 'z'){
				if(find(lst.begin(), lst.end(), ch) == lst.end()){
					if(dir){
						lst.push_front(ch);
					}else{
						lst.push_back(ch);
					}
				}
			}else if(ch == '<'){
				dir = true;
			}else if(ch == '>'){
				dir = false;
			}
		}
		
		for(list< char >::iterator it = lst.begin(); it != lst.end(); ++it){
			cout << (char)(*it);
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	string base,a,b,c;
	int n;
	int f[27];
	for(cin>>n;n>0;n--){
		cin>>base;
		a=b=c="";
		for(int i=0;i<=26;i++)f[i]=0;
		for(int i=0;i<base.size();i+=3){
			if(f[base[i]-96]==0){
				f[base[i]-96]=1;
				if(a.size()==0)a+=base[i];
				else{
					if(base[i-1]=='>')a+=base[i];
					else{
						b=a;
						a="";
						a+=base[i];
						a+=b;
					}
				}
			}
			
		}
		cout<<a<<endl;
		
	}
	
	return 0;
}

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

int main(){
  int i,j,k,n;
  string log;

  cin >> n;
  
  for( i=0;i<n;i++ ){
    char train[52]={NULL};
    int m=25;
    cin >> log;
    train[m]=log[0];
    for( j=3;j<log.size();j+=3 ){
      if(log[j-1] == '>'){
	m++;
	train[m] = log[j];
      }else{
	m--;
	train[m] = log[j];
      }
    }
    for(k=0;k<52;k++){
      if(train[k] >= 'a' && train[k] <= 'z' ){
	cout << train[k];
      }
    }
    cout << endl;
    log.erase();
  }

  return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n,p,check;
    char s[1024];
    while(cin >> n){
        rep(j,n){
            p = 350;
            check = 0;
            char ans[700] = {'0'};
            cin >> s;
            for(int i = 0; s[i]; i++){
                if(s[i] >= 'a' && s[i] <= 'z'){
                    ans[p] = s[i];
                }else if(s[i] == '>'){
                    p++;
                }else if(s[i] == '<'){
                    p--;
                }
            }
            rep(i,700){
                if(ans[i] == '0'){
                    continue;
                }else if(ans[i] >= 'a' && ans[i] <= 'z'){
                    cout << ans[i];
                }
            }cout << endl;
        }
    }
}

C++: 
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  rep(j,n){
    string s;
    cin>>s;
    vi a(26,0);
    string ans="";
    ans+=s[0];
    a[s[0]-'a']++;
    for(i=1;i<s.size();i+=3)if(a[s[i+2]-'a']==0){
      if(s[i]=='-')ans=ans+s[i+2];
      else ans=s[i+2]+ans;
      a[s[i+2]-'a']++;
    }
    cout<<ans<<endl;
  }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;



//??????
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int j = 1; j < N; j++) cout << ", " << v[j]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()



int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string str;
		cin >> str;
		
		char _train[2048] = {};
		char* train = &_train[1024];

		int pos = 0;
		train[pos] = str[0];

		for (int j = 0; j < str.size() / 3; j++) {
			int index = 3 * j + 1;
			if (str.substr(index, 2) == "->")
				pos++;
			else
				pos--;
			train[pos] = str[index + 2];
		}

		string ans;
		for (int j = -1000; j < 1000; j++) {
			if (train[j] != 0) ans.push_back(train[j]);
		}
		
		cout << ans << endl;
	}

	return 0;
}