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>

void 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;
	}
}

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

int main(){

char x,y,c,p[1025];
int N;
string str,S;
scanf("%d",&N);
for(int i=0;i<N;i++){
cin>>str;
int R=1024,L=1024,T=1024;
for(int i=0;i<str.size();i+=3)
{if(i==0)S=str[0];
else {
if(str[i-1]=='>'){T++;if(T>R){S=S+str[i];R=T;}}
else if(str[i-1]=='-'){T--;if(T<L){S=str[i]+S;L=T;}}
}
}
cout<<S<<endl;
}
return 0;
}

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

char t[10000];
char ans[100];
int p,len;
int i,n;

int main(){
  scanf("%d",&n);
  while(n>0){
    n--;
    for(i=0;i<100;i++)ans[i]=' ';
    
    scanf("%s",t);
    len=strlen(t);
    
    p=50;
    ans[p]=t[0];
    for(i=3;i<len;i+=3){
      if(t[i-1]=='>')p++;
      else p--;
      ans[p]=t[i];
    }
    
    for(i=0;i<100;i++)
      if(ans[i]!=' ')
        printf("%c",ans[i]);
    printf("\n");
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <sstream>
#include <functional>
#include <list>
#include <iterator>
using namespace std;

int main()
{
	int n;
	cin>>n;
	while(n--){	
		string s;
		char c[690];
		fill(c,c+690,'-');
		int fro=345,now=345;
		cin>>s;
		c[now]=s[0];
		for(int i=3;i<(int)s.length();i+=3){
			char tmp=s[i];
			if(s[i-1]=='>'){
				c[++now]=tmp;
			}else if(s[i-1]=='-'){
				now--;
				if(c[now]=='-'){
					fro=now;
					c[now]=tmp;
				}
			}
		}
		for(int i=fro;c[i]!='-';i++){
			cout<<c[i];
		}
		cout<<endl;
	}
    return 0;
}

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

int main(){
	char c[100];
	string s;
	int n, k;

	cin >> n;
	for(int i=0 ; i<n ; i++){
		cin >> s;
		
		for(int j=0 ; j<100 ; j++) c[j] = '_';
		k = 50;

		c[k] = s[0];		
		for(int j=0 ; j<s.size()/3 ; j++){
			if( s[j*3+1] == '-' ){
				k++;
				c[k] = s[j*3+3];
			}else if( s[j*3+1] == '<' ){
				k--;
				c[k] = s[j*3+3];
			}
		}
		for(int j=0 ; j<60 ; j++){
			if( c[j] != '_' ) cout << c[j];
		}
		cout << endl;
	}
}

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

int c (string str, int dir, int cursor, char a) {
    for (int i = cursor; 0 <= i && i < str.size(); i += dir) {
        if (a == str[i]) {
            return i;
        }
    }

    return cursor + dir;
}

int main ()
{
    string str;
    int n;
    cin >> n;
    while (n--) {
        cin >> str;
        int cursor = 0;
        string res = "";

        res += str[0];

        for (int i = 1; i < str.size()-2; i += 3) {
            if (str[i] == '-') {
                cursor = c(res, 1, cursor, str[i+2]);
                if (res.size() == cursor) {
                    res += str[i+2];
                }
            } else if (str[i] == '<') {
                cursor--;
                cursor = c(res, -1, cursor, str[i+2]);
                if (cursor < 0) {
                    res = str[i+2] + res;
                    cursor = 0;
                }
            }
        }

        cout << res << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int now;
char st[1024];

void add_str(char d){
  int len=strlen(st);
  for(int i=len;i>now;i--){
    st[i]=st[i-1];
  }
  st[now]=d;
  return;
}

void af(char d){
  if(st[now+1]==d){
    now++;
    return;
  }else{
    st[now+1]=d;
    now++;
    return;
  }
}

void bf(char d){
  if(now-1>=0&&st[now-1]==d){
    now--;
    return;
  }else{
    add_str(d);
    return;
  }
}
int main(void){
  int n;
  char d,way[3];
  cin>>n;
  getchar();
  for(int i=0;i<n;i++){
    now=0;
    memset(st,'\0',sizeof(st));
    st[0]=getchar();
    while(true){
      way[0]=getchar();
      if(way[0]=='\n')break;
      way[1]=getchar();
      way[2]='\0';
      d=getchar();
      if(!strcmp(way,"->")){
        af(d);
      }else{
	bf(d);
      }
    }
    printf("%s\n",st);
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int nex[26];
bool app[26],aft[26];
int main(){
	int n;
	cin>>n;
	for(int u=0;u<n;u++){
	string s;
	cin>>s;
	for(int i=0;i<26;i++)app[i]=false,nex[i]=114514,aft[i]=false;
	for(int i=0;i<s.size();i++){
		if(s[i]>='a'&&s[i]<='z')app[s[i]-'a']=true;
	}
	for(int i=0;i<s.size()-1;i+=3){
		if(s[i+1]=='-'){
			nex[s[i]-'a']=s[i+3]-'a';
			aft[s[i+3]-'a']=true;
		}
		else{
			nex[s[i+3]-'a']=s[i]-'a';
			aft[s[i]-'a']=true;
		}
	}
	int t=0;
	while(true){
		if(app[t]&&!aft[t])break;
		t++;
	}
	while(true){
		char z=t+'a';
		cout<<z;
		t=nex[t];
		if(t==114514)break;
	}
	cout<<endl;
	}
	return 0;
}

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

int main()
{
	std::deque<char> train;
	std::string str;
	int n;
	
	std::cin>>n;
	for(int i=0;i<n;i++)
	{
		std::cin>>str;
		int pos=0,max=0,min=0;
		train.clear();
		train.push_back(str[0]);

		for(int k=1;k<str.size();k++)
		{
			if(str[k]=='-')
			{
				pos++;
			}
			else
			{
				pos--;
			}
			k+=2;
			if(pos>max)
			{
				train.push_back(str[k]);
				max=pos;
			}
			else if(pos<min)
			{
				train.push_front(str[k]);
				min=pos;
			}
		}
		
		while(!train.empty())
		{
			std::cout<<train.front();
			train.pop_front();
		}
		std::cout<<std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main( void )
{
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ )
	{
		string train;
		cin >> train;

		string kotae = "";
		int c = 1;
		kotae += train[0];

		while ( c < train.size() )
		{
			if ( train[c] == '-' )
			{
				if ( kotae.find( train[c+2] ) == string::npos )
				{
					kotae += train[c+2];
				}
			}
			else if ( train[c] == '<' )
			{
				if ( kotae.find( train[c+2] ) == string::npos )
				{
					kotae = train[c+2] + kotae;
				}
			}
			c += 3;
		}
		cout << kotae << endl;
	}
	return 0;
}