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<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	while(n--){
		string s="";
		string in;
		cin>>in;
		s+=in[0];
		int q=0;
		int qq=1;
		while(in.size()!=qq){
			if(in[qq]=='<'){
				qq+=2;
				if(q)q--;
				else s.insert(s.begin(),in[qq]);
			}else{
				qq+=2;
				if(q!=s.size()-1)q++;
				else {s+=in[qq];q++;}
			}
			qq++;
		}
		cout<<s<<endl;
	}
}

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

int main(){
	int n;
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		string s;
		cin >> s;
		int now=0; //文字列の位置
		int p=26; //現在の車両位置
		
		char train[60];
		memset(train, '0', sizeof(train));
		
		while(now<s.size()){
			if('a'<=s[now] && s[now]<='z'){ //文字だったら
				train[p]=s[now++];	
			}
			else{ //矢印だったら
				if(s[now] == '-') p++;
				else if(s[now] == '<') p--;
				now+=2;
			}
		}
		
		int t=0;
		while(train[t]=='0') t++;
		while(train[t]!='0') printf("%c", train[t++]);
		printf("\n");			
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i;
  string s,a;
  
  cin>>n;
  for(int j=0;j<n;++j){
  cin>>s;
  a=s[0];
  int pos=0;
  for(i=3;i<s.size();i+=3){
    if(s[i-1]=='>'){
      if(s[i]==a[pos+1]){
	pos++;
	continue;
      }
      a+=s[i];
      pos++;
    }else if(s[i-1]=='-'){
      if(s[i]==a[pos-1]){
	pos--;
	continue;
      }
      a=s[i]+a;
      pos--;
      if(pos<0) pos=0;
    }
  }
  cout<<a<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;
typedef vector<ll> V;

ll n;
string s, ans;
bool f;

int main(){
	cin >> n;
	while (n--){
		cin >> s;
		ans += s[0];
		for (int i = 1; i < s.size(); i += 3){
			f = 0;
			REP(j, ans.size()){
				if (ans[j] == s[i + 2]){
					f = 1;
				}
			}
			if (f)continue;
			if (s[i] == '-'){
				ans += s[i + 2];
			}
			else{
				ans = s[i + 2] + ans;
			}
		}
		cout << ans << endl;
		ans.clear();
	}
}

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

typedef vector<int> VI;
typedef vector<VI> VII;
typedef pair<int, int> PII;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back;
#define MP make_pair
#define SIZE(a) int((a).size())
#define SORT(c) sort((c).begin(), (c).end())

const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 3;

int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

string solve(string &input){
  string train(input, 0, 1);
  int f = 0, b = 0, n = 0;
  for(int i = 1; i < input.size(); i++){
    if(input[i] == '<') n++;
    else if(input[i] == '>') n--;
    else if(input[i] != '-' && n > f) { train.insert(train.begin(), input[i]); f = n;}
    else if(input[i] != '-' && n < b) { train.insert(train.end(), input[i]); b = n;}
  }
  return train;
}

int main(void){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    string input;
    cin >> input;
    cout << solve(input) << endl;
  }
  return 0;
}

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

int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		char line[2048],str[1024]={0};
		cin >> line;
		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 <cstdio>
#include <cctype>
#include <utility>
#include <deque>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, int &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

int main() {
	for (int n {in()}; n; n--) {
		deque<int> l = {gcu()};
		for (int c, i {}; (c = gcu()) != '\n';) {
			int d {c == '-' ? 1 : -1};
			gcu();
			int n {gcu()};
			if (i + d == (int)l.size()) {
				l.push_back(n);
				i++;
			} else if (i + d < 0)
				l.push_front(n);
			else
				i += d;
		}
		for (int i: l)
			out((char)i);
		outl();
	}
}