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 <cstring>
#include <string>
using namespace std;

enum{
	FORWARD,
	BACK,
};

class Train
{
public:
	Train( char first ) : m_conductor( 0 )
	{
		memset( m_train, 0, sizeof(m_train) );
		m_train[ FORWARD ][ 0 ] = first;
	}
	~Train(){}

	void move( int d, char mark ){
		switch( d ){
			case FORWARD:
				++m_conductor;
				break;
			case BACK:
				--m_conductor;
				break;
		}

		int direction, conductor;
		if( m_conductor < 0 ){
			direction = BACK;
			conductor = -( m_conductor + 1 );
		}else{
			direction = FORWARD;
			conductor = m_conductor;
		}
		m_train[ direction ][ conductor ] = mark;
	}

	void output()
	{
		for( int i = 25; i >= 0; --i ){
			char c;
			if( c = m_train[ FORWARD ][ i ] ){
				cout << c;
			}
		}
		for( int i = 0; i < 26; ++i ){
			char c;
			if( !( c = m_train[ BACK ][ i ] ) ){
				break;
			}
			cout << c;
		}
		cout << endl;
	}

private:
	char m_train[ 2 ][ 26 ];
	int m_conductor;
};

int main()
{
	int n;
	while( cin >> n ){
		for( int i = 0; i < n; ++i ){
			string s;
			cin >> s;

			Train train( s[ 0 ] );

			int ptr = 1, size = s.size();

			int d = FORWARD;
			while( ptr < size ){
				d = s[ ptr++ ] == '<' ? FORWARD : BACK;
				ptr++;
				char c = s[ ptr++ ];
				train.move( d, c );
			}
			train.output();
		}
	}
	return 0;
}

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

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

using namespace std;

int main(){
  int i, j, n;
  string str, train;
  string::iterator iter;

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> str;
    train.push_back(str[0]);

    for(j=1, iter=train.begin(); j<str.size(); j+=3){
      if(str[j] == '<' && str[j+1] == '-'){
	if(iter == train.begin()){
	  train.insert(train.begin(), str[j+2]);
	  iter = train.begin();
	}else{
	  --iter;
	}
      }else if(str[j] == '-' && str[j+1] == '>'){
	if(iter == train.end()-1){
	  train.push_back(str[j+2]);
	  iter = train.end()-1;
	}else{
	  ++iter;
	}
      }
    }

    cout << train << endl;
    train.clear();
  }

  return 0;
}

C++: #include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin.ignore();
  for(int i=0;i<n;i++){
    getline(cin,s);
    char c = s[0];
    char c1,c2,c3,c4;
    int j = 0;
    map<char,char> m;
    while(s[j+1]!='\0'){
      c1 = s[j];
      c2 = s[j+1];
      c3 = s[j+2];
      c4 = s[j+3];
      j += 3;
      if(c2=='<'){
	if(c==c1)
	  c = c4;
	m[c4] = c1;
      }
      else if(c3=='>')
	m[c1] = c4;
    }
    cout << c;
    while(m[c]!=0){
      cout << m[c];
      c = m[c];
    }
    cout << endl;
  }
  return 0;
}

C++: #define scanf_s scanf
#include<iostream>
#include <deque>
using namespace std;
#define MAX 1025
int main()
{
	int n;
	char str[MAX];
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		int now = 0;
		deque<char> qu;
		scanf_s("%s", str, MAX);
		for (int j = 0; str[j] != '\0'; ++j) {
			if ('a' <= str[j] && str[j] <= 'z') {
				if (qu.empty() || now  == (int)qu.size()) {
					qu.push_back(str[j]);
				}
				else if(now == -1){
					qu.push_front(str[j]);
					++now;
				}
			}
			if (str[j] == '>') { ++now; }
			else if (str[j] == '<') { --now; }
		}
		for (int k = 0; k < (int)qu.size(); ++k) {
			printf("%c", qu[k]);
		}
		printf("\n");
	}
}

C++: // 2011/02/06 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	int n;
	cin >> n;

	for(int i=0; i<n; i++){
		string str;
		cin >> str;

		char train[52];
		for(int j=0; j<52; j++)
			train[j] = '/';

		int trn_i = 26;
		train[trn_i] = str[0];

		for(int j=1; j<str.size();){
			if(str[j]=='-'&&str[j+1]=='>')
				trn_i++;
			else if(str[j]=='<'&&str[j+1]=='-')
				trn_i--;
			j += 2;

			train[trn_i] = str[j];
			j++;
		}

		for(int j=0; j<52; j++)
			if(train[j]!='/')
				cout << train[j];
		cout << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
//#include <map>
#include <iomanip>
#include <vector>

using namespace std;



string in;
int now, max_i, min_i;
char syaryo[1024];

void saiki(string in)
{
	string yajirusi;
	
	yajirusi = in.substr(0, 2);
	if (yajirusi == "") return;
	if (yajirusi == "->")
	{
		now++;
		max_i = max(now, max_i);
		syaryo[now] = in.substr(2, 1).c_str()[0];
		saiki(in.substr(3));
	} else {
		now--;
		min_i = min(now, min_i);
		syaryo[now] = in.substr(2, 1).c_str()[0];
		saiki(in.substr(3));
	}
}

int main()
{
	int n;
	
	cin >> n;
	for (int i=0; i<n; i++)
	{
		cin >> in;
		now = max_i = min_i = 512;
		syaryo[now] = in[0];
		saiki(in.substr(1));
		for (int j=min_i; j<=max_i; j++)
		{
			cout << syaryo[j];
		}
		cout << endl;
	}
	
	return 0;
}

C++: #define scanf_s scanf
#include <stdio.h>
#include<iostream>
#include <deque>
using namespace std;
#define MAX 1025
int main()
{
	int n;
	char str[MAX];
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		int now = 0;
		deque<char> qu;
		scanf_s("%s", str, MAX);
		for (int j = 0; str[j] != '\0'; ++j) {
			if ('a' <= str[j] && str[j] <= 'z') {
				if (qu.empty() || now  == (int)qu.size()) {
					qu.push_back(str[j]);
				}
				else if(now == -1){
					qu.push_front(str[j]);
					++now;
				}
			}
			if (str[j] == '>') { ++now; }
			else if (str[j] == '<') { --now; }
		}
		for (int k = 0; k < (int)qu.size(); ++k) {
			printf("%c", qu[k]);
		}
		printf("\n");
	}
}

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

using namespace std;

int n;
string str;

int main()
{
    cin >> n;
    while (n-- > 0) {
        cin >> str;
        int len = str.size();
        char t[26][2]; // front back
        for (int i = 0; i < 26; i++)
            t[i][0] = t[i][1] = -1;

        for (int i = 3; i < len; i+= 3) {
            int a = str[i - 3] - 'a', b = str[i] - 'a';
            if (str.substr(i - 2, 2) == "->") {
                t[a][1] = b;
                t[b][0] = a;
            } else {
                t[a][0] = b;
                t[b][1] = a;
            }
        }

        int s = -1;
        for (int i = 0; i < 26; i++) {
            if (t[i][0] == -1 && t[i][1] != -1) {
                s = i;
                break;
            }
        }

        do {
            printf("%c", s + 'a');
            s = t[s][1];
        } while (s != -1); 
        
        if (n != 1) 
            cout << endl;
    }    
}