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<bits/stdc++.h>
using namespace std;

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        string s;
        cin >> s;
        deque<char> deq;
        set<char> st;
        bool back = false;
        for(int j=0;j<s.size();++j){
            if(s[j] == '<'){
                back = false;
                j++;
            }else if(s[j] == '-'){
                back = true;
                j++;
            }else{
                if(st.count(s[j]))continue;
                if(back)deq.push_back(s[j]);
                else deq.push_front(s[j]);
                st.insert(s[j]);
            }
        }
        for(auto c: deq){
            cout << c;
        }
        cout << endl;
    }

    return 0;
}

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

using namespace std;

int main(void){
  int n;

  cin >> n;
  cin.ignore();
  for(int i=0;i<n;i++){
	map<int,char> m;
	int pos=0;
	string str;
	char tmp[2];

	
	getline(cin,str);
	int len = str.size();

	for(int j=0;j<len;j++){
	  if(m.find(pos) == m.end()){
		m[pos] = str[j];
	  }
	  if(j == len-1) break;
	  tmp[0] = str[++j];
	  tmp[1] = str[++j];
	  if(tmp[0] == '-'){
		pos++;
	  }else{
		pos--;
	  }
	}
	map<int,char>::iterator it = m.begin();

	while(it != m.end()){
	  cout << (*it).second;
	  ++it;
	}
	cout << endl;
  }
}

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

#define repeat(n, i) for(int i = 0; i < (n); i++)

int main() {
    int n; cin >> n;
    repeat(n, i) {
        string s; cin >> s;
        list<char> train;
        bool which = false; // right: false, left: true
        map<char, bool> used;
        for (string::iterator si = s.begin(); si != s.end(); si++) {
            if (*si == '-') continue;
            if (*si == '<') {
                which = true;
            } else if (*si == '>') {
                which = false;
            } else if (!used[*si]) {
                used[*si] = true;
                if (which) {
                    train.push_front(*si);
                } else {
                    train.push_back(*si);
                }
            }
        }
        for (list<char>::iterator li = train.begin(); li != train.end(); li++) {
            cout << *li;
        }
        cout << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	char train[2048];
	int n;
	cin>>n;
	while(n--){
		int x=0;
		string s,ans;
		cin>>s;
		ans+=s[0];
		for(int i=0;i<(s.length()-1)/3;i++){
			int k=i*3+1;
			if(s[k]=='<'){
				if(x==0){
					string tmp=s[k+2]+ans;
					ans=tmp;
				}else x--;
			}else if(s[k+1]=='>'){
				if(ans[x+1]!=s[k+2]){
					ans+=s[k+2];
					x++;
				}else x++;
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    string s, res;
    for(;n--;){
      cin >> s;
      res = s.substr(0, 1);
      int now = 0;
      for(i = 2;i < s.size();i += 3){
        if(now == res.size() - 1 && s[i] == '>'){
          res = res + s.substr(i + 1, 1);
          ++now;
        }else if(now == 0 && s[i - 1] == '<'){
          res = s.substr(i + 1, 1) + res;
        }else{
          if(s[i] == '>')++now;
          else --now;
        }
      }
      pri(res);

      s.clear();
      res.clear();
    }


/*/

//*/ break;
  }
  return 0;
}

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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){

  int n;
  cin>> n;
  while(n--){
    int cnt=0;
    string s;
    map<int,char> m;
    cin>> s;
    for(int i=0;i<s.size();i++){
      if(isalpha(s[i])) m[cnt]=s[i];
      else if(s[i]=='<') cnt--;
      else if(s[i]=='>') cnt++;
    }

    for(map<int,char>::iterator it=m.begin();it!=m.end();it++){
      cout<< (*it).second;
    }

    cout<< endl;
  }
}

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

int main()
{
  int n;
  cin>>n;
  for(;n--;)
    {
      string s;
      cin>>s;
      string ans="";
      ans+=s[0];
      int now=0;
      if(s.size()>2 && s[1]=='-')
	now++;
      else
	now--;
      for(int i=3;i<s.size();i+=3)
	{	  
	  if(now<0)
	    {
	      ans=s[i]+ans;
	      now++;
	    }
	  else if(now>=ans.size())
	    {
	      ans+=s[i];	     
	    }
	  
	  if(i+1<s.size()-1)
	    {
	      if(s[i+1]=='-')
		now++;
	      else
		now--;
	    }
	}
      cout<<ans<<endl;
      
    }
}

C++: #include <iostream>
#include <map>

using namespace std;

int main()
{
    int n;
    
    cin >> n;
    while (n--) {
        string inp;
        map<int, char> m;
        int idx = 0;

        cin >> inp;

        m[idx] = inp[0];
        for (int i = 1; i < inp.size(); i += 3) {
            if (inp[i] == '-') 
                m[++idx] = inp[i + 2];
            else if (inp[i + 1] == '-') 
                m[--idx] = inp[i + 2];
        }
        
        map<int, char>::iterator it = m.begin();
        for ( ; it != m.end(); it++) 
            cout << (*it).second;
        cout << endl;
    }

    return 0;
}