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 <string>
#include <vector>
class Sharyou {
	Sharyou *prev, *back;
public:
	char ch;
	Sharyou(const char &c = ' ') :prev{ nullptr }, back{ nullptr }, ch{ c } {};
	void set_prev(Sharyou &p) {
		prev = &p;
	}
	void set_back(Sharyou &b) {
		back = &b;
	}
	std::string to_s() const {
		auto front = top();
		return front.to_string();
	}
private:
	Sharyou top() const {
		if (prev) {
			return prev->top();
		}
		else {
			return (*this);
		}
	}
	std::string to_string(std::string res = "") const {
		res.push_back(ch);
		if (back) {
			return back->to_string(res);
		}
		else {
			return res;
		}
	}
};
std::vector<Sharyou> init() {
	std::vector<Sharyou> vector(26);
	char ch = 'a';
	for (auto i = 0; i < 26; ++i, ++ch) {
		vector.at(i).ch = ch;
	}
	return vector;
}
int main() {
	int n;
	std::cin >> n;
	for (; n > 0; --n) {
		std::string str;
		std::cin >> str;
		std::vector<Sharyou> vector = init();
		for (auto i = 3; i < str.size(); i += 3) {
			switch (str.at(i - 1)) {
			case '>':
				vector.at(str.at(i) - 'a').set_prev(vector.at(str.at(i - 3) - 'a'));
				vector.at(str.at(i - 3) - 'a').set_back(vector.at(str.at(i) - 'a'));
				break;
			case '-':
				vector.at(str.at(i) - 'a').set_back(vector.at(str.at(i - 3) - 'a'));
				vector.at(str.at(i - 3) - 'a').set_prev(vector.at(str.at(i) - 'a'));
			}
		}

		std::cout << vector.at(str.at(0) - 'a').to_s() << '\n';
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
char T[2000000]; int length = 1000000, n; string S;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int i = 0; i < 2000000; i++) {
			T[i] == ' ';
		}
		length = 1000000;
		cin >> S;
		for (int i = 0; i <= S.size() / 3; i++) {
			T[length] = S[i * 3];
			if (S.size() != i) {
				if (S[i * 3 + 1] == '-') {
					length++;
				}
				else {
					length--;
				}
			}
		}
		for (int i = 0; i < 2000000; i++) {
			if (T[i] != ' ') {
				cout << T[i];
			}
		}
		cout << endl;
	}
}

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

string solve(string s) {
	string ret = "";

	int indx = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == '-')
			continue;
		else if(s[i] == '>') {
			indx++;
		}
		else if(s[i] == '<') {
			indx--;
		}
		else {
			if(indx < 0) {
				ret.insert(ret.begin(), s[i]);
				indx = 0;
			}

			else if(indx == ret.size()) {
				ret.push_back(s[i]);
			}
		}
	}

	return ret;
}

int main() {
	int n;

	cin >> n;
	for(int i = 0; i < n; i++) {
		string s;
		cin >> s;
		cout << solve(s) << endl;
	}

	return 0;
}

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

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    long long int n;
    
    std::cin >> n;

    for (; n--;) {
        std::string str, train;
        std::cin >> str;
        bool is_back = false;
        std::map<char, int> m;
        for (unsigned int i = 0; i < str.size(); i += 3) {
            if (m[str[i]]++ == 0) {
                if (is_back) {
                    train += str[i];
                }
                else {
                    train = str[i] + train;
                }
            }
            
            if (i + 1 != str.size()) {
                if (str[i + 1] == '-') {
                    is_back = true;
                }
                else {
                    is_back = false;
                }
            }
        }
        std::cout << train << std::endl;
    }

    return 0;
}

C++: #include<iostream>
#include<list>
#include<string>
using namespace std;int main(){int i;string s;list<char> l;list<char>::iterator x;getline(cin,s);while(getline(cin,s)){l.clear();l.push_back(s[i=0]);x=l.begin();while(++i<s.size()){if(s[i++]=='<'&&*--x!=s[++i]){l.insert(++x,s[i]);x--;}if(s[i]=='>'&&*++x!=s[++i]){l.insert(x,s[i]);x--;}}for(x=l.begin();x!=l.end();)cout<<*x++;cout<<endl;}return 0;}

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

using namespace std;

int n;
int c[2][30];
int x[30];
bool used[30];
int sx,bx;

void dfs(int v,int nx){
	if(used[v])return;
	used[v]=true;
	x[v]=nx;
	sx=min(sx,nx);
	bx=max(bx,nx);
	if(c[0][v]!=-1)dfs(c[0][v],nx-1);
	if(c[1][v]!=-1)dfs(c[1][v],nx+1);
}

int main(void){
	scanf("%d",&n);
	for(int kkk=0;kkk<n;kkk++){
		memset(c,-1,sizeof(c));
		memset(used,false,sizeof(used));
		memset(x,0,sizeof(x));
		string s;
		cin >> s;
		int a,b,m=-1;
		for(int i=0;i<s.size();i++){
			if(s[i]>='a' && s[i]<='z'){
				a=b;
				b=s[i]-'a';
				if(m==1)c[0][b]=a,c[1][a]=b;
				if(m==0)c[1][b]=a,c[0][a]=b;
			}
			if(s[i]=='>')m=1;
			if(s[i]=='<')m=0;
		}
		sx=bx=0;
		dfs(s[0]-'a',0);
		for(int i=sx;i<=bx;i++){
			for(int j=0;j<=25;j++){
				if(x[j]==i && used[j])printf("%c",j+'a');
			}
		}
		cout << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		char str[2048];
		scanf("%s", str);
		deque<int> train;
		int pos = 0;
		train.push_front(str[0]);
		reep(i, 1, strlen(str)){
			if(str[i+1] == '>')
				++pos;
			else
				--pos;
			i += 2;
			if(pos < 0){
				train.push_front(str[i]);
				pos = 0;
			}else if(train.size() <= pos){
				train.push_back(str[i]);
			}
		}
		
		rep(i, train.size())
			putchar(train[i]);
		puts("");
	}
	return 0;
}

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

int main(){
	char c[100];
	string s;
	int n, k;

	cin >> n;
	for(int i=0 ; i<n ; i++){
		cin >> s;
		
		for(int j=0 ; j<100 ; j++) c[j] = '_';
		k = 50;

		c[k] = s[0];		
		for(int j=0 ; j<=s.size()/3 ; j++){
			if( s[j*3+1] == '-' ){
				k++;
				c[k] = s[j*3+3];
			}else if( s[j*3+1] == '<' ){
				k--;
				c[k] = s[j*3+3];
			}
		}
		for(int j=0 ; j<60 ; j++){
			if( c[j] != '_' ) cout << c[j];
		}
		cout << endl;
	}
}

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

    int n;
    cin>>n;
    while(n--){
        int least=30,most=30,now=30;
        string str;
        char ans[60];
        cin>>str;
        ans[30]=str[0];
        for(int i=3;i<str.size();i+=3){
            if(str[i-1]=='>'){
                now++;
                if(most<now)most++;
            }
            else{
                now--;
                if(least>now)least--;
            }
            ans[now] = str[i];
            if(most-least==25)break;
        }
        for(int i=least;i<=most;i++)cout<<ans[i];
        cout<<endl;

    }

    return 0;
}