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>
using namespace std;

int main()
{
  int n;
  cin >> n;
  char cars[53];
  for (int dataset =0; dataset<n; dataset++)
  {
    int now_car = 26;
    int first_car = 26;
    int end_car = 26;
    bool flag = true;
    char op;
    while(flag)
    {
      char car;
      cin >> car;
      if ( car == '-' || car == '<' )
      {
        op = car;
      }
      else 
      {
        cars[now_car] = car;
        cin >> op;
      }
      if ( cin.eof() )
      {
        break;
      }
      switch (op)
      {
      case '<':     //  前方への移動
        now_car--;
        if ( now_car < first_car )
        {
          first_car = now_car;
        }
        cin >> op;    //  矢印をひとつ捨てる
        break;
      case '-':
        now_car++;
        if ( end_car < now_car )
        {
          end_car = now_car;
        }
        cin >> op;    //  矢印をひとつ捨てる
        break;
      default:
        flag = false;
        break;
      } //switch(op)
    } //while(flag)

    for (int i=first_car; i<=end_car; i++)
    {
      cout << cars[i] << flush;
    }
    cout << endl;
    cars[26] = op;
  } //for
}

C++: #include <cstdio>
#include <cstring>
using namespace std;
#define RBSIZE 400

int main() {
  int n, p, h, t;
  char rb[RBSIZE];
  char c, ar[2];
  scanf("%d\n", &n);
  for (int i=0; i<n; i++) {
    memset(rb, (char)-1, RBSIZE);
    p = h = t = 0;
    rb[p] = getchar();
    while (1) {
      ar[0] = getchar();
      if (ar[0] == '\n' || ar[0] == EOF) break;
      ar[1] = getchar();
      c = getchar();
      if (ar[0]=='-') {
        p = (p+1)%RBSIZE;
        if (rb[p] == -1) {
          t = p;
        }
      } else {
        p = (p+RBSIZE-1)%RBSIZE;
        if (rb[p] == -1) {
          h = p;
        }
      }
      rb[p] = c;
    }
    p = h;
    while (1) {
      putchar(rb[p]);
      if (p == t) break;
      p = (p+1)%RBSIZE;
    }
    putchar('\n');
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    int n;
	cin >> n;
	
	while(n--)
	{
		string line;
		cin >> line;
		
		vint train(100, 0);
		
		
		int now = 50;
		train[now] = line[0];
		
		
		rep(i, line.size() / 3)
		{
			now += (line[i * 3 + 2] == '>' ? 1 : -1);
			
			if(!train[now])
				train[now] = line[i * 3 + 3];
		}
		
		
		for(int i = 1; !(train[i - 1] != 0 && train[i] == 0); i++)
		{
			if(train[i] != 0) cout << (char)train[i];
		}
		
		if(n) cout << endl;
	}
}

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

int main(){
  int i,j,n,k,max;
  string str,ans;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> str;
    ans = str[0];
    k = 0;
    max = 1;
    for(j=2;j<str.size();j+=3){
      if(str[j] == '>'){
	k++;
	if(k == max){
	ans += str[j+1];
	max++;
	}
      }
      else if(str[j-1] == '<'){
	if(k == 0){
	  ans = str[j+1] + ans;
	  max++;
	}
	else k--;
      }
    }

    cout << ans << endl;

  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(void){
	int n;

	cin >> n;
	for(int i = 0; i < n; ++i){
		int nowPos = 0;
		int dir = 0;
		string train;
		string s;
		cin >> s;

		train += s[0];
		for(unsigned int j = 1; j < s.length(); ++j){
			if( s[j] == '<' ){
				--nowPos;
				++j;
			}else if( s[j] == '-' ){
				++nowPos;
				++j;
			}else{
				if( nowPos >= (signed)train.length() ){
					train += s[j];
					nowPos = train.length() - 1;
				}else if( nowPos < 0 ){
					train.insert( train.begin(), s[j] );
					nowPos = 0;
				}
			}
		}
		cout << train << '\n';
	}
	return 0;
}

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

int main() {
    int T; cin >> T;
    cin.ignore();

    while(T--) {
        string line;
        getline(cin, line);
        line += "@";

        deque<char> Q;
        int cur = 0;
        int front = 0;
        int back = 0;
        int p = 0;

        Q.push_back(line[0]);
        p++;

        while(true) {
            if(line[p] == '@') break;

            if(line[p] == '<') {
                cur--;
                p += 2;

                if(!(front <= cur && cur <= back)) {
                    Q.push_front(line[p]);
                    front = cur;
                }

                p++;
            }
            else {
                cur++;
                p += 2;

                if(!(front <= cur && cur <= back)) {
                    Q.push_back(line[p]);
                    back = cur;
                }

                p++;
            }
        }

        while(!Q.empty()) {
            cout << Q.front();
            Q.pop_front();
        }
        cout << endl;
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n;
  cin>>n;
  while(n--){
    set<char> use;
    string str;
    string ans;
    cin>>str;
    ans += str[0];
    use.insert(str[0]);
    for(int i=3;i<(int)str.size();i+=3){
      if(use.find(str[i])!=use.end()) continue;
      if(str[i-1]=='>') ans += str[i];
      else ans = str[i]+ans;
      use.insert(str[i]);
    }
    cout<<ans<<endl;
  }

  return 0;
}