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 <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string train;
string str;
void calc(){
	train=str[0];
	map<char,int> data;
	data.clear();
	data[str[0]]++;
	for(int i =0;i <str.length();){
		if(isalpha(str[i])){
			string tmp =str.substr(i+1,2);
			i+=3;
			if(tmp=="->"){
				if(data[str[i]])continue;
				train =train+str[i];
				data[str[i]]++;
			}else{
				if(data[str[i]])continue;
				train =str[i]+train;
				data[str[i]]++;
			}
		}
	}
}


int main(){
	int n;
	cin>>n;
	cin.ignore();
	rep(i, n){
		getline(cin, str);
		calc();
		cout <<train<<endl;
	}
	return 0;
}

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

int main(){
    int n,cnt;
    string s;
    cin >> n;
    while(n--){
        map <int,char> data;
        map <int,char>::iterator itr;
        cnt = 0;
        cin >> s;
        for(int i=0;i<s.length();i++){
            if(isalpha(s[i])){
                data.insert(map<int,char>::value_type(cnt,s[i]));
            }
            else if(s[i] == '<') cnt--;
            else if(s[i] == '>') cnt++;
        }
        for(itr=data.begin();itr!=data.end();itr++){
            cout << itr->second;
        }
        cout << endl;
    }
}

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

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string line;
		cin >> line;
		deque<char> t;
		t.push_back(line[0]);
		unsigned index = 0;
		for (unsigned i = 1; i < line.size(); i++) {
			switch (line[i]) {
			case '-':
				i += 2;
				index++;
				if (index == t.size()) {
					t.push_back(line[i]);
				}
				break;
			case '<':
				i += 2;
				if (index == 0) {
					t.push_front(line[i]);
				}
				else index--;
			}
		}
		for (unsigned i = 0; i < t.size(); i++) {
			cout << t[i];
		}
		cout << endl;
	}
	return 0;
}

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

int main()
{
    int n;
    string str;
    char t[100];

    cin >> n;

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

        for( int j = 0; j < 100; j++ )
            t[j] = '0';        

        int k = 50;
        for( int j = 0; j < str.size(); j++ )
        {
            if( t[k] != str[j] )
                t[k] = str[j];

            if( j + 1 < str.size() && str[j+1] == '-' )
                k++;
            else if( j + 1 < str.size() )
                k--;
            else;

            j += 2;
        }
            
        for( int j = 0; j < 100; j++ )
            if( t[j] != '0' )
                cout << t[j];
        cout << endl;
    }


    return 0;
}

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

int check(char s[100], char c){
	for(int i=0 ; i < 100 ; i++ ){
		if( s[i] == c ) return i;
	}
	return -1;
}

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

		char f[100];
		for(int i=0 ; i < 100 ; i++ )
			f[i] = '*';
		f[50] = s[0];

		for(int i=1 ; i < s.size() ; i+=3 ){
			char prev = s[i-1];
			char next = s[i+2];
			int j = check( f , prev );
			if( s[i] == '-' ){
				f[j+1] = next;
			}
			if( s[i] == '<' ){
				f[j-1] = next;
			}
		}
		for(int i=0 ; i < 100 ; i++ ){
			if( f[i] != '*' ){
				cout << f[i];
			}
		}
		cout << endl;
	}
}

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

void compute(string line){
    char buffer[2100];
    int p = 1025;
    int l = p, r = p;
    buffer[p] = line[0];
    for ( int i = 3; i < line.size(); i+=3 ){
	if ( line[i-1] == '>' ) p++;
	else p--;
	buffer[p] = line[i];
	l = min(l, p); r = max(r, p);
    }
    for ( int i = l; i <= r; i++ ) cout << buffer[i];
    cout << endl;
}

main(){
    int tcase; cin >> tcase;
    string line;
    for ( int i = 0; i < tcase; i++ ) { cin >> line; compute(line); }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>

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

using namespace std;

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

	rep(i,n)
	{
		string s;
		cin >> s;

		vector<char> v;
		v.push_back(s[0]);
		int now = 0;

		rep(j,s.size())
		{
			if('a' <= s[j] && s[j] <= 'z')
			{
				int flag = 0;

				if(s[j+1] == '-' && s[j+2] == '>')
				{
					flag = 1;
				}
				else if(s[j+1] == '<' && s[j+2] == '-')
				{
					flag = 2;
				}

				if(flag == 1)
				{
					if('a' <= s[j+3] && s[j+3] <= 'z')
					{
						if(now == v.size() -1)
						{
							v.push_back(s[j+3]);
							now++;
						}
						else
						{
							now++;
						}
					}
				}
				else if(flag == 2)
				{
					if('a' <= s[j+3] && s[j+3] <= 'z')
					{
						if(now == 0)
						{
							vector<char> temp;
							std::copy(v.begin(),v.end(),std::back_inserter(temp));

							v[0] = s[j+3];
							v.resize(1);

							rep(h,temp.size())
							{
								v.push_back(temp[h]);
							}
						}
						else
						{
							now--;
						}
					}
				}
				else
				{
					break;
				}
			}

			if(j+3 == s.size()-1)
			{
				break;
			}
			else
			{
				j += 2;
			}
		}

		rep(j,v.size())
		{
			cout << v[j];
		}
		cout << endl;
	}
	return 0;
}

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

int main(void) {
    int n, p;
    string d, r;

    for (cin >> n; n > 0; --n) {
        cin >> d;
        r = d[0];
        p = 0;
        for (int i = 1; i < d.length(); i += 3) {
            if (d.substr(i, 2) == "->") {
                try {
                    if (r.at(p+1) != d[i+2]) r = r + d[i+2];
                }
                catch(out_of_range&) {
                    r = r+d[i+2];
                }
                ++p;
            }
            else {
                try {
                    if (r.at(p-1) != d[i+2]) r = d[i+2] + r;
                }
                catch(out_of_range&) {
                    r = d[i+2] + r;
                }
                if (p > 0) --p;
            }
            cout << r << endl;
        }
        cout << r << endl;
    }
    return 0;
}