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++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


#ifdef _DEBUG
#define typeof(X) std::identity<decltype(X)>::type //C++0x (for vs2010)
#else
#define typeof(X) __typeof__(X) // for gcc
#endif

#define sz(a)  int((a).size())
#define FOREACH(it, c) for (typeof((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define FOR(i,count) for (int i = 0; i < (int)(count); i++)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
const int MODULO = 100000 ;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

using namespace std;

int main()
{
	int n; cin>>n;
	while(n--){
		string s; cin>>s;
		char c[100] = {};
		int i = 0,l = 50;
		for(; i * 3 < sz(s); i++){
			c[l] = s[i*3];
			if(3*i+1 < sz(s)){
				if(s[3*i+1] == '-') l++;
				else l--;
			}
		}
		while(c[l-1]) l--;
		puts(c+l);
	}
	return 0;
}

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); 
        cout << endl;
    }    
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
long n,i,j,m;
string s,t;
cin>>n;
for(i=0;i<n;i++){
cin>>s;
m=s.size();t=s[0];
for(j=0;j*3+3<m;j++){
if(t.find(s[j*3+3])==string::npos){
if(s[j*3+2]=='>')t+=s[j*3+3];
else t.insert(0,1,s[j*3+3]);
}
}
cout<<t<<endl;
}
return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<char,int> P;

class mycmp{
public:
	bool operator() (const P p1,const P p2){
		return p1.second < p2.second;
	}
};

int main(){

	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		for(int i=0;i<n;i++){
			string str;
			cin >> str;

			vector<P> order;
			map<char,int> data;		
			set<char> alpha;

			for(int j=0;j<str.size();j++){
				if(isalpha(str[j])){
					alpha.insert(str[j]);
				}
			}

			int j=0;
			for(set<char>::iterator it = alpha.begin(); it != alpha.end(); it++){
				data[*it]=j++;
			}

			for(int k=0;k<alpha.size();k++){
				for(int j=0;j+3<str.size();j+=3){
					string tmp = str.substr(j,4);
					if(tmp.substr(1,2)=="<-"){
						if(data[tmp[0]] < data[tmp[3]]){
							swap(data[tmp[0]],data[tmp[3]]);
						}
					}
					else if(tmp.substr(1,2)=="->"){
						if(data[tmp[0]] > data[tmp[3]]){
							swap(data[tmp[0]],data[tmp[3]]);
						}
					}
				}
			}

			for(map<char,int>::iterator it = data.begin(); it != data.end();it++){
				order.push_back(P(it->first,it->second));
			}

			sort(order.begin(),order.end(),mycmp());

			for(vector<P>::iterator it = order.begin(); it != order.end();it++){
				cout << it->first;
			}

			cout << endl;
		}
	}
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		string s,ss;
		cin>>s;
		int p=0;
		for(int j=0;j<s.size();++j){
			if(s[j]=='>')++p;
			else if(s[j]=='<')--p;
			else if('a'<=s[j]&&s[j]<='z'){
					if(p==-1){
						ss=s[j]+ss;
						p=0;
					}else if(p==ss.size())ss=ss+s[j];
			}
		}
		cout<<ss<<"\n";
	}
	return 0;
}

C++: #include <stdio.h>
#include <ctype.h>
int main(void){
    int n,i,o,min,max,t;
    char line[1025],line1[52];
    scanf("%d",&n);
    for(i=0;min=t=25,max=26,i<n;i++){
        scanf("%s",line);
        line1[min]=line[0];
        for(o=3;line[o];o++)
            if(isalpha(line[o])){
                if(line[o-1] == '>'){
                    line1[++t]=line[o];
                    if(max==t)
                        max++;
                }
                else{
                    if(min==t)
                        min--;
                    line1[--t]=line[o];
                }
            }
        line1[max]=0;
        printf("%s\n",line1+min);
    }
    return 0;
}

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

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

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

int main() {
	int N;
	cin >> N;
	while (N--) {
		string str;
		cin >> str;

		list<char> dt;
		list<char>::iterator it = dt.begin();
		bool r;
		dt.push_back(str[0]); it++;
		for (int i=1; i<str.size(); i++)
			if (i%3==0)
				if (r) {
					if (it == --dt.end()) dt.push_back(str[i]);
					it++;
				} else { 
					if (it == dt.begin()) dt.push_front(str[i]);
					it--;
				}
			else
				r = (str[i++]=='-') ? true : false;

		it = dt.begin();
		while (it != dt.end())
			cout << *(it++);
		cout << endl;
	}
	return 0;
}