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"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define R 1
#define L -1


int main(){
	int n;
	cin>>n;
	rep(loop,n){
		string s;
		cin>>s;
		string ans = string(1,s[0]);
		int now=0;
		for(int i=1;i<s.size();i+=3){
			int alph = s[i+2];
			int dir;
			if(s[i+1]=='>'){dir = R;now++;}
			else {dir = L;now--;}

			if( now==-1){
				now = 0;
				if(dir == R)ans=ans+string(1,alph);
				else ans = string(1,alph)+ans;
			}else if(now==ans.size()){
				now = now--;
				if(dir == R)ans=ans+string(1,alph);
				else ans = string(1,alph)+ans;
			}
		}
		cout<<ans<<endl;
	}
}

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

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

int main() {
  int Tc;
  scanf("%d", &Tc);
  scanf("%*c");
  while(Tc--) {
    char c;
    list<char> v;
    list<char>::iterator it;
    scanf(" %c", &c);
    v.push_back(c);
    it = v.begin();
    while(scanf("%c", &c), c != '\n') {
      scanf("%c", &c);
      if(c == '>') {
        ++it;
        if(it == v.end()) it = v.insert(it, ' ');
      } else {
        if(it == v.begin()) it = v.insert(it, ' ');
        else --it;
      }
      scanf("%c", &c);
      *it = c;
    }
    for(it = v.begin(); it != v.end(); ++it) printf("%c", *it);
    puts("");
  }
  return 0;
}

C++: // 0130
#include <iostream>
#include <deque>
#include <string>
const int C = 'a';
using namespace std;

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

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

		deque<char> dq;
		dq.push_back(str[0]);
		int ch[26] = {0};
		ch[str[0]-C]++;

		for(int j=1;j<str.length();j+=3){
			if((str[j] == '-') && (str[j+1] == '>') && (ch[str[j+2]-C] == 0)){
				dq.push_back(str[j+2]);
				ch[str[j+2]-C]++;
			}

			if((str[j] == '<') && (str[j+1] == '-') && (ch[str[j+2]-C] == 0)){
				dq.push_front(str[j+2]);
				ch[str[j+2]-C]++;
			}
		}

		for(deque<char>::iterator itr = dq.begin();itr != dq.end();itr++)
			cout<<*itr;
		cout<<endl;

	}
	
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#include<tuple>
#include<stack>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;


bool used[30];

int main() {

	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		deque<char> que;

		char fr = s[0];
		char bk = s[0];

		que.push_back(s[0]);
		used[s[0] - 'a'] = 1;
		for (int i = 0; i < s.size(); i += 3)
		{
			if (i == 0)
			{
				continue;
			}
			if (s[i - 1] == '>')
			{
				if (used[s[i] - 'a'] == 0)
				{
					que.push_back(s[i]);
					used[s[i] - 'a'] = 1;
				}
				bk = s[i];
				
			}
			else
			{
				if (used[s[i] - 'a'] == 0)
				{
					que.push_front(s[i]);
					used[s[i] - 'a'] = 1;
				}
				fr = s[i];
			}
		}

		int cnt = 0;
		for (auto itr : que)
		{
			if (cnt == 0)
			{
				cout << itr;
			}
		}
		cout << endl;

		for (int i = 0; i < 30; i++)
		{
			used[i] = 0;
		}
		que.clear();
	}

	return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

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

    while(n--){
        string in, res; cin >> in;
        res = in.at(0);

        for(int i = 3; i < in.size(); i += 3){
            string cur = in.substr(i, 1);

            if(~res.find(cur)) continue;
            switch(in.at(i - 2)){
                case '-':
                    res = res + cur;
                    break;
                case '<':
                    res = cur + res;
                    break;
            }
        }
        cout << res << endl;
    }

    return 0;
}

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

int main()
{
    int n;
    string s;
    std::getline(cin, s);
    n = std::stoi(s);
    for(int i = 0; i < n; i++)
    {
        string ans;
        string in_str;
        bool is_appeared[26] = {};
        std::getline(cin, in_str);
        ans.push_back(in_str[0]);
        is_appeared[in_str[0] - 'a'] = true;
        for(int j = 1; j < in_str.length() - 2; j = j + 3)
        {
            if(is_appeared[in_str[j + 2] - 'a'])
            {
                continue;
            }
            else
            {
                is_appeared[in_str[j + 2] - 'a'] = true;
            }

            if(in_str[j] == '-' && in_str[j + 1] == '>')
            {
                ans.push_back(in_str[j + 2]);
            }
            else if(in_str[j] == '<' && in_str[j + 1] == '-')
            {
                ans.insert(ans.begin(), in_str[j + 2]);
            }
            else
            {
                /* Nop */
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
  int in;
  cin >> in;
  char trash;
  scanf("%c",&trash);
  for(int i = 0; i < in; i++){
    string str;
    getline(cin,str);
    string out;
    out += str[0];
    for(int j = 1; j < str.length(); j+=3){
      if(str[j+1] == '>'){
	int status = 1;
	for(int k = 0; k < out.length(); k++){
	  if(out[k] == str[j+2]) status = 0;
	}
	if(status) out += str[j+2];
      }
      if(str[j] == '<'){
	int status = 1;
	for(int k = 0; k < out.length(); k++){
	  if(out[k] == str[j+2]) status = 0;
	}
	if(status){
	  string sub;
	  sub += str[j+2];
	  sub += out;
	  out = sub;
	}
      }
    }
    cout << out << endl;
  }
  return 0;
}