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 R(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int i,k=1500,m2=1500,m1=1500;
    char a[3000];
    string s;
    cin>>s;
    a[k]=s[0];
    for(i=1;i<s.size();i+=3){
      if(s[i]=='-')k--;
      else k++;
      a[k]=s[i+2];
      m1=max(m1,k);
      m2=min(m2,k);
    }
    for(i=m1;i>=m2;i--)cout<<a[i];
      cout<<endl;
  }
}

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 <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<char, char> P;

int main() {
  int N; cin >>N;
  REP(n, N){
    string str; cin >>str;
    if(str.length() == 1){
      cout <<str <<endl;
      continue;
    }
    map<char, P> m;
    set<char> s;
    for(int i = 0; i + 3 < (int)(str.length()); i += 3){
      char c = str[i], next = str[i + 3];
      if(s.find(c) == s.end()) m[c] = P('A', 'A');
      if(s.find(next) == s.end()) m[next] = P('A', 'A');
      s.insert(c);
      s.insert(next);
      if(str[i + 2] == '>'){
        m[c].second = next;
        m[next].first = c;
      } else{
        m[c].first = next;
        m[next].second = c;
      }
    }
    char now = 'A';
    for(map<char, P>::iterator it = m.begin(); it != m.end(); ++it) if(it->second.first == 'A') now = it->first;
    while(now != 'A'){
      cout <<now;
      now = m[now].second;
    }
    cout <<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
char T[1000000]; int length = 500000, n; string S;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int i = 0; i < 1000000; i++) {
			T[i] == ' ';
		}
		length = 500000;
		cin >> S;
		for (int i = 0; i <= S.size() / 3; i++) {
			T[length] = S[i * 3];
			if (S.size() != i) {
				if (S[i * 3 + 1] == '-') {
					length++;
				}
				else {
					length--;
				}
			}
		}
		for (int i = 0; i < 1000000; i++) {
			if (T[i] != ' ') {
				cout << T[i];
			}
		}
		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];
	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 if (buf[i + 1] == '<')
				--relaPos;
		}
		sort(pos, pos+26);
		for (int i = 0; pos[i].first != 9999; ++i)
			putchar(pos[i].second);
		putchar('\n');
	}

	return 0;
}

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

int main(void){
	int i,n,now,from,to;
	char c,rst[64];

	cin>>n;
	getchar();
	while(n--){
		now = from = to = 26;
		while((c=getchar()) != '\n'){
			if(isalpha(c)) rst[now] = c;
			else{
				if((c=getchar()) == '>'){
					now++;
					if(now > to) to++;
				}
				else{
					now--;
					if(now < from) from--;
				}
			}
		}
		for(i=from;i<=to;i++) cout<<rst[i];
		cout<<endl;
	}

	return 0;
}

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

int main(){
	int n,pos;
	char train[60];
	string s;
	cin >> n;
	getchar();
	for(int i = 0;i < n;i++){
		pos = 30;
		for(int j = 0;j < 60;j++) train[j] = 0;
		getline(cin,s);
		train[pos] = s[0];
		for(int j = 1;j < s.size();j++){
			if(s[j] == '-') {
				j += 2;
				train[++pos] = s[j];
			}
			else if(s[j] == '<'){
				j += 2;
				train[--pos] = s[j];
			}
		}
		for(int j = 0;j < 60;j++){
			if(train[j] != '\0') cout << train[j];
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int n;	cin>>n;
	while(n--){
		string tr;	cin>>tr;
		deque<char> dq(1,tr[0]);
		deque<char>::iterator it=dq.begin();

		for(int i=1;i<tr.length();i+=3){
			if(tr[i]=='-'){	// forward
				it++;
				if(it==dq.end())	dq.push_back(tr[i+2]);
			}
			else{			// backward
				if(it==dq.begin())	dq.push_front(tr[i+2]);
				it--;
			}
		}

		for(it=dq.begin();it!=dq.end();it++)	cout<<*it;
		cout<<endl;
	}

	return 0;
}

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


using namespace std;


int main()
{
	int n;
	string t;
	list<char> l;

	ios::sync_with_stdio(false);

	cin >>n;

	for (int i = 0; i != n; ++i)
	{
		cin >> t;
		l.push_back(t.at(0));
		for (unsigned int j = 1; j != t.size();++j)
		{
			if (t.at(j) == '>')
			{
				if (find(l.begin(),l.end(),t.at(j + 1)) == l.end())
				{
					l.push_back(t.at(j + 1));
				}
				
			}
			else if(t.at(j)=='<')
			{
				if (find(l.begin(), l.end(), t.at(j + 2)) == l.end())
				{
					l.push_front(t.at(j + 2));
				}
			}
		}
		for (list<char>::iterator it=l.begin(); it != l.end(); ++it)
		{
			cout << *it;
		}
		cout << endl;
		l.clear();
	}

	return 0;

}

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

using namespace std;

int main() {
	char c[1025];
	int i,n,k;
	list<char> tr;
	list<char>::iterator it;
	cin >> n;
	for (n;n>0;n--) {
	  cin >> c; 
	  k=strlen(c);
	  tr.push_back(c[0]);
	  it=tr.begin();
	  for (i=0;i<k-3;i+=3) { 
		  if (c[i+1]=='-') {it++; if (it==tr.end()) { it--; tr.push_back(c[i+3]); it++;}}
		  else { if (it==tr.begin()) tr.push_front(c[i+3]); it--;}
	  }
	  for (it=tr.begin();it!=tr.end();it++) cout << *it; cout << endl;
	  tr.clear();
	}
	return 0;
}