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 <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    int n;
	cin >> n;
	
	while(n--)
	{
		string line;
		cin >> line;
		
		vint train(100, 0);
		
		
		int now = 50;
		train[now] = line[0];
		
		
		rep(i, line.size() / 3)
		{
			now += (line[i * 3 + 2] == '>' ? 1 : -1);
			
			if(!train[now])
				train[now] = line[i * 3 + 3];
		}
		
		
		for(int i = 1; !(train[i - 1] != 0 && train[i] == 0); i++)
		{
			if(train[i] != 0) cout << (char)train[i];
		}
		
		cout << endl;
	}
}

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

bool Search(deque<char>& rdeqc, char c) {
  for (deque<char>::iterator itc = rdeqc.begin(); itc != rdeqc.end(); itc++) {
    if(*itc == c) return true;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    deque<char> deq;
    for(int j = 0; j < s.size(); j++) {
      if(j == 0) deq.push_front(s[j]);
      if(j%3 == 2) {
	if(Search(deq, s[j+1])) continue;
	if(s[j] == '>') deq.push_back(s[j+1]);
	else deq.push_front(s[j+1]);
      }
    }
    
    for(int i = 0; i < deq.size(); i++) cout << deq[i];
    cout << endl;
  }
}

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(260, -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');
    // }
    int i = distance(f.begin(), find(all(f), 1));
    for (;;) {
      //   cout << char(i + 'a');
      i = t[i];
      if (i == -1) break;
    }
    cout << endl;
  }
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  rep(i,n){
    cin >> s;
    string ans ="";
    auto it = find(all(s),'-');
    while(it != s.end()){
      s.erase(find(all(s),'-'),it+1);
      it = find(all(s),'-');
    }
    ans += s[0];
    int dir = 0;
    set<char> cs;
    cs.insert(s[0]);
    REP(i,1,s.size()){
      if(s[i] == '<'){
        dir = -1;
      }
      else if(s[i] == '>'){
        dir = 1;
      }
      else{
        if(dir == 1 && cs.find(s[i]) == cs.end()){
          ans += s[i];
          cs.insert(s[i]);
        }
        else if(dir == -1 && cs.find(s[i]) == cs.end()){
          ans = s[i] + ans;
          cs.insert(s[i]);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}