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>
#include <list>

int main()
{
	int n; std::cin >> n;
	for (int i=0; i<n; i++) {
		std::string input;
		std::cin >> input;
		std::list<char> cars;
		cars.push_back(input[0]);
		std::list<char>::iterator it = cars.begin();
		for (int k=3; k<input.length(); k+=3) {
			char c = input[k];
			bool right = (input.substr(k-2,2) == "->");
			if (right) {
				++it;
				if (it == cars.end()) {
					cars.push_back(c); it = cars.end(); --it;
				}
			}
			else {
				if (it == cars.begin()) {
					cars.push_front(c); it = cars.begin();
				}
				else --it;
			}
		}
		for (it = cars.begin(); it != cars.end(); ++it) {
			std::cout << *it;
		}
		std::cout << std::endl;
	}
				
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <deque>

using namespace std;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		char visited[255] = {};
		string input;
		cin >> input;

		visited[input[0]] = 1;
		deque<char> output;
		output.push_back(input[0]);
		for (int i = 1; input[i]; i += 3){
			if (!visited[input[i + 2]]){
				if (input[i] == '-') output.push_back(input[i + 2]);
				else output.push_front(input[i + 2]);
				visited[input[i + 2]] = 1;
			}
		}
		for (int i = 0; i < output.size(); i++){
			cout << output[i];
		}
		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 <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-5;

using namespace std;

int main()
{
	char buf[1024 + 256];
	cin.getline(buf, sizeof(buf));
	int n;
	sscanf(buf, "%d", &n);
	while (n--)
	{
		cin.getline(buf, sizeof(buf));
		strcat(buf, "--");
		pair<int, char> pos[26];
		for (int i = 0; i < 26; ++i)
		{
			pos[i].first = 9999;
			pos[i].second = i + 'a';
		}
		int relaPos = 0;
		for (int i = 0; buf[i] != '\0'; i += 3)
		{
			pos[buf[i] - 'a'].first = relaPos;
			if (buf[i + 2] == '>')
				++relaPos;
			else
				--relaPos;
		}
		sort(pos, pos+26);
		for (int i = 0; pos[i].first != 9999 && i < 26; ++i)
			putchar(pos[i].second);
		putchar('\n');
	}

	return 0;
}

C++: #include <iostream>
#include <queue>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int n;
	cin >> n;
	while(n--) {
		deque<char> q;
		bool ch[26] = {};
		string s;
		cin >> s;
		q.push_back(s[0]);
		ch[s[0]-'a'] = 1;
		int ren = (s.length()-1)/3;
		rep2(i,1,ren+1) {
			if(s[i*3-2] == '<' && !ch[s[i*3]-'a']) {
				q.push_front(s[i*3]);
				ch[s[i*3]-'a'] = 1;
			} else if(s[i*3-1] == '>' && !ch[s[i*3]-'a']) {
				q.push_back(s[i*3]);
				ch[s[i*3]-'a'] = 1;
			}
		}
		for(char c : q) {
			cout << c;
		}
		cout << endl;
	}
	return 0;
}

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

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	cin>>n;
	rep(i,n){
		string s;
		cin>>s;
		string ans=s.substr(0,1);
		int c=0;
		while(1){
			// cout<<s[c]<<endl;
			if(c>=s.size()-1) break;
			string t=s.substr(c+1,2);
			if(t=="->"&&ans[ans.size()-1]==s[c]){
				ans=ans+s.substr(c+3,1);
			}
			else if(t=="<-"&&ans[0]==s[c]){
				ans=s.substr(c+3,1)+ans;
			}
			c+=3;
		}
		cout<<ans<<endl;
	}
}