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++: // 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');
      i = t[i];
      if (i == -1) break;
    }
    cout << endl;
  }
}

C++: #include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n;
    string str;
    cin >> n;
    rep(i, n)
    {
        char c[100] = {0};
        cin >> str;
        int index = 30;
        int move = 0;
        rep(j, str.size())
        {
            if ((int)(str[j] - 'a') >= 0 && (int)(str[j] - 'z') <= 0)
            {
                c[index] = str[j];
            }
            else if (str[j] == '<')
            {
                move = -1;
                index += move;
            }
            else if (str[j] == '>')
            {
                move = 1;
                index += move;
            }
            else
            {
                continue;
            }
        }
        rep(j, 100)
        {
            if (c[j] != 0)
                cout << c[j];
        }
        cout << endl;
    }
    return 0;
}

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

int main()
{
	char line[2048];
	while(cin >> line)
	{
		char str[1024]={0};
		for(int i=0,j=500; line[i]; i++)
		{
			switch(line[i])
			{
				case '>': j++; break;
				case '<': j--; break;
				case '-': break;
				default: str[j]=line[i]; break;
			}
		}

		int i;
		for(i=0; !str[i]; i++);
		cout << &str[i] << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main(){

	char table[3000];
	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		memset(table,0,sizeof(table));
		string str;
		cin>>str;
		int pos=1500;
		table[pos]=str[0];
		for(int j = 1; j < str.size(); j+=3){
			if(str.substr(j,2)=="->"){
				pos++;
				table[pos]=str[j+2];
			}
			else{
				pos--;
				table[pos]=str[j+2];
			}
		}
		for(int j = 0; j < 3000; j++){
			if(table[j]!=0){
				cout<<table[j];
			}
		}
		cout<<endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include <string.h>

// int search(char[], char, int);
// void swap(char[], int, int);
void pre_connect(char[], char, int);

int main (){
    int n, i, j, count, idx;
    char str[1024], line[60], train;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%s",str);

        line[0] = str[0];
        count = 1;
        idx=0;
        for(j=2; j<strlen(str); j+=3){
            if(str[j] == '>'){
                if(line[idx+1] == str[j+1]){
                    idx++;
                } else {
                    line[count++] = str[j+1];
                    idx++;
                }
            } else {
                if(line[idx-1] == str[j+1]){
                    idx--;
                } else {
                    pre_connect(line, str[j+1], count);
                    count++;
                }
            }
        }
        line[count] = '\0';
        printf("%s\n", line);
    }
    return 0;
}

/* 
int search(char line[], char t, int count){
    int i;

    for(i=0; i<count; i++){
        if(line[i] == t){
            return i;
        }
    }
    return -1;
}

void swap(char line[], int i, int j){
    char tmp;
    tmp = line[i];
    line[i] = line[j];
    line[j] = tmp;
}
*/

void pre_connect(char line[], char t, int count){
    int i;
    char new[60];

    new[0] = t;

    for(i=1; i<=count; i++){
        new[i] = line[i-1];
    }
    new[i] = '\0';

    strcpy(line, new);
}

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

int l,r;
char t[3000];

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

	while(n--){
		string s;
		cin>>s;
		int idx = 1500;
		l = r = 1500;
		for(int i=0;i<s.length();i+=3){
			if(i != 0){
				if(s[i-1] == '>') idx++;
				else idx--;
				l = min(l,idx);
				r = max(r,idx);
			}
			t[idx] = s[i];
		}
		for(int i=l;i<=r;i++){
			cout<<t[i];
		}
		cout<<endl;
	}

	return 0;
}