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<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,now;
	string s,ans,res;
	cin>>n;
	rep(p,n){
		if(p==0)cin.ignore();
		getline(cin,s);
		ans=s[0];
		now=0;
		for(int i=1;i<s.size();i+=3){
			res=s[i];
			res+=s[i+1];
			if(res=="->"){
				if(now==ans.size()-1){
					ans+=s[i+2];
					now++;
				}else now++;
			}else{
				if(now==0){
					ans=s[i+2]+ans;
				}else now--;
			}
		}
		cout<<ans<<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');
    // }
    int i = distance(f.begin(), find(all(f), 1));
    for (;;) {
      cout << char(i + 'a');
      break;
      // i = t[i];
      // if (i == -1) break;
    }
    cout << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <set>
#include <list>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		set<char> marked;
		list<char> train;
		string str;
		cin >> str;
		train.push_back(str[0]);
		marked.insert(str[0]);
		for(int i = 1; i < str.size(); i += 3)
		{
			if(str[i] == '-' && str[i + 1] == '>')
			{
				if(marked.find(str[i + 2]) == marked.end())
				{
					marked.insert(str[i + 2]);
					train.push_back(str[i + 2]);
				}
			}
			else if(str[i] == '<' && str[i + 1] == '-')
			{
				if(marked.find(str[i + 2]) == marked.end())
				{
					marked.insert(str[i + 2]);
					train.push_front(str[i + 2]);
				}
			}
		}
		list<char>::iterator it = train.begin();
		while(it != train.end())
		{
			cout << *it;
			++it;
		}
		cout << endl;
	}
}

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

C++: //16
#include<iostream>
#include<deque>

using namespace std;

int main(){
  int n;
  cin>>n;
  while(n--){
    char l[1025];
    cin>>l;
    deque<char> deq;
    deq.push_back(l[0]);
    int idx=0;
    for(int i=1;l[i];i+=3){
      if(l[i]=='-'){
	idx++;
	if(idx>=deq.size()){
	  deq.push_back(l[i+2]);
	}
      }else{
	idx--;
	if(idx<0){
	  deq.push_front(l[i+2]);
	  idx=0;
	}
      }
    }
    for(int i=0;i<deq.size();i++){
      cout<<deq[i];
    }
    cout<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

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

string solve() {
  string in, ret;
  cin >> in;
  const int sz = in.size();
  ret.insert(0, 1, in[0]);
  for (int i = 0; i < sz; i+=3) {
    if (i == sz-1) {
      continue;
    } else {
      int l = -1;
      rep (j,ret.size()) if (in[i] == ret[j]) { l = j; break; }
      char c = in[i+3];
      if (in[i+2] == '>') {
        if (l == ret.size() - 1) {
          ret.insert(l+1, 1, c);
        }
      } else {
        if (l == 0) {
          ret.insert(l, 1, c);
        }
      }
    }
  }
  return ret;  
}

int main() {
  int n;
  cin >> n;
  rep (i,n) cout << solve() << endl;
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

void solve() {
    string s, ans = "";
    cin >> s;
    for (int i = 0; i < s.size(); i += 3) {
        if (ans.find(s[i]) != string::npos) continue;
        if (!i) ans = ans + s[i];
        else if (s[i - 1] == '>') ans = ans + s[i];
        else if (s[i - 2] == '<') ans = s[i] + ans;
    }
    cout << ans << endl;
}

int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        solve();

    return 0;
}

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

int main()
{
    int n;
    cin >> n;

    for(int i = 0; i < n; i++)
    {
        string in_str;
        string ans;
        bool is_checked[26] = {};
        cin >> in_str;
         
        ans.push_back(in_str[0]);
        is_checked[in_str[0] - 'a'] = true;
        for(int j = 1; j < in_str.size() - 2; j = j + 3)
        {
            if(is_checked[in_str[j + 2] - 'a'])
            {
                continue;
            }

            is_checked[in_str[j + 2] - 'a'] = true;

            if(in_str[j] == '-' && in_str[j + 1] == '>')
            {
                ans.push_back(in_str[j + 2]);
            }
            else if(in_str[j] == '<' && in_str[j + 1] == '-')
            {
                ans.insert(ans.begin(), in_str[j + 2]);
            }
            else
            {
                /* Nop */
            }
        }
        cout << ans << endl;
    }
    return 0;
}