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

int main() {
	int n; cin >> n;
	rep(i, n) {
		string s; cin >> s;
		deque<char>que; que.push_back(s[0]);
		int pos = 0, look = 1;
		while (look + 2 < s.size()) {
			if (s[look + 1] == '>') {
				if (++pos >= que.size()) {
					que.push_back(s[look + 2]);
				}
			}
			else {
				if (pos - 1 < 0) {
					que.push_front(s[look + 2]);
				}
				else pos--;
			}
			look += 3;
		}
		for (char c : que) {
			cout << c;
		}
		cout << endl;
	}
}

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

int main(){
	int n;
	std::cin >> n;
	for (int i = 0; i < n; i++){
		char train[30];
		for (int j = 0; j < 30; j++)train[j] = '?';
		int it = 14;

		std::string str;
		std::cin >> str;

		train[it] = str[0];
		for (int j = 1; j < str.size(); j++){
			if (str[j] == '>'){
				it++;
				if (train[it] != str[j + 1])train[it] = str[j + 1];
			}
			else if (str[j] == '<'){
				it--;
				if (train[it] != str[j + 2])train[it] = str[j + 2];
			}
		}

		for (int j = 0; j < 30; j++){
			if (train[j] != '?')std::cout << train[j];
		}
		std::cout << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <list>
using namespace std;
int main()
{
  int n,i,l;
  string s;
  list<char> ls;
  list<char>::iterator is,ie;
  cin >> n;
  while(n--){
    ls.clear();
    cin >> s;
    ls.push_back(s[0]);
    l = s.length();
    is = ie = ls.begin();
    for(i=1; i<l; i+=3){
      string t = s.substr(i,2);
      if(t == "->" && *ie == s[i-1]){
	ls.push_back(s[i+2]);
	ie = ls.end();
	ie--;
      }else if(t == "<-" && *is == s[i-1]){
	ls.push_front(s[i+2]);
	is = ls.begin();
      };
    }
    is = ls.begin();
    while(is != ls.end()){
      cout << *is;
      is++;
    }
    cout << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <map>
int main(){
	int n;
	std::cin >> n;
	std::string s;
	while(n--){
		std::cin >> s;
		int pos = 0;
		while(pos = s.find("-", pos), pos != std::string::npos){
			s.replace(pos, 1, "");
		}

		std::map<char, char> m, rm;
		for(int i=1;i<s.size();i+=2){
			if(s[i] == '>')
				m[s[i+1]] = s[i-1], rm[s[i-1]] = s[i+1];
			else
				m[s[i-1]] = s[i+1], rm[s[i+1]] = s[i-1];
		}

		char end = (*m.begin()).first;
		while(m[end] != 0){
			end = m[end];
		}
		//whileI¹_ÅendÍstartÆÈé

		while(rm[end] != 0){
			std::cout << end;
			end = rm[end];
		}
		std::cout << end << '\n';
	}
}

C++: #include <iostream>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)

int main(){
	int n;
	cin >> n;
	while(n--){
		int pos = 0 , l = 0 , r = 0;
		map<int,char> g;
		string s;
		cin >> s;
		for(int i=0;i<s.size();i+=3){
			g[pos] = s[i];
			if(i == s.size()-1)break;
			if(s[i+1] == '<')pos--;
			else pos++;
		}
		for(map<int,char>::iterator it = g.begin(); it != g.end();++it)
			cout << it->second ;
		cout << endl;
	}
}

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

int main()
{
    int n;
    string s;
    cin >> n;
    std::getline(cin, s);
    for(int i = 0; i < n; i++)
    {
        string ans;
        string in_str;
        bool is_appeared[26] = {};
        std::getline(cin, in_str);
        ans.push_back(in_str[0]);
        is_appeared[in_str[0] - 'a'] = true;
        for(int j = 1; j < in_str.length() - 2; j++)
        {
            if(is_appeared[in_str[j + 2] - 'a'])
            {
                continue;
            }
            else
            {
                is_appeared[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;
}

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

int main()
{
	int n;
	std::cin >> n;
	
	while( n-- )
	{
		std::string s;
		std::cin >> s;

		std::deque<char> deq;
		deq.push_back( s[0] );
		
		int p = 0;
		bool used[53];
		memset( used, false, sizeof( used ) );
		used[26] = true;

		for( int i = 1; i < s.size(); i += 3 )
		{
			if( s[i] == '<' && !used[--p + 26] )
				deq.push_front( s[i+2] );
			else if( s[i+1] == '>' && !used[++p + 26] )
				deq.push_back( s[i+2] );

			used[p + 26] = true;
		}

		for( auto it = deq.begin(); it != deq.end(); ++it )
			std::cout << *it;

		std::cout << std::endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string d;
    int in=0;
    cin>>d;
    s=d[0];
    for(int j=1;j<d.size();){
      if(d[j]=='-'&&in+1==s.size()){s+=d[j+2];in++;}
      else if(d[j]=='-')s[++in]=d[j+2];
      else if(in<=0)s=d[j+2]+s;
      else s[--in]=d[j+2];
      j+=3;
      //cout<<s<<endl;
    }
    cout<<s<<endl;
  }

}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <list>
using namespace std;

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

int main() {
  int n;
  cin >> n;
  cin.ignore();
  while(n--) {
    string s;
    getline(cin,s);
    list<char> train;
    train.push_back(s[0]);
    int a = 0;
    for(int i=1; i<s.length();i+=3) {
      if (s[i] == '-') a++;
      else a--;
      if (a<0) {
        train.push_front(s[i+2]);
        a = 0;
      }
      if (a>=train.size())
        train.push_back(s[i+2]);
    }
    FOR(it,train)
      cout << *it;
    cout << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<map>
#include<cstdio>
#include<cctype>
using namespace std;
int main(){
  int n,cnt;
  string str;
  map<int,char> data;
  cin >> n;
  while(n--){
    cnt = 0;
    cin >> str;
    for(int i=0,l=str.size();i<l;i++){
      if(isalpha(str[i])) data[cnt] = str[i];
      else if(str[i]=='<') cnt--;
      else if(str[i]=='>') cnt++;
    }
    for(map<int,char>::iterator it = data.begin(),l = data.end();it!=l;it++){
      cout << (*it).second;
    }
    cout << endl;
    data.clear();
  }
}

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

int main(void){
  int n;
  string str;
  cin>>n;
  getline(cin,str);
  while(n--){
    getline(cin,str);
    int ind = 0;  
    string res = str.substr(0,1);
    for(int i = 0 ; i < str.size() + 1 ; i ++){
      
      if(str[i] == '>'){
	ind++;
	//cout<<'>';
	if(ind >= res.size()){
	  res = res + str[i + 1];
	}
      }else if(str[i] == '<'){
	//cout<<'<';
	ind--;
	if(ind < 0){;
	  res = str[i + 2] + res;
	  ind = 0;
	}
      }
    }
    cout<<res<<endl;
  }
}