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>

using namespace std;

int main(void){

  int n;
  cin >> n;

  while(n--){

    string s;
    string ans;

    cin >> s;
    ans = s[0];

    for( int i = 1 ; i < s.size() ; i++ ){

      if( 'a' <= s[i] && s[i] <= 'z' ){

	if( s[i - 1] == '>' ){
	  for( int j = 0 ; j < ans.size() ; j++ ){
	    if( s[i] == ans[j] ) goto back;
	  }
	  ans = ans + s[i];
	}

	else if( s[i - 1] == '-' ){
	  for( int j = 0 ; j < ans.size() ; j++ ){
	    if( s[i] == ans[j] ) goto back;
	  }
	  ans = s[i] + ans;
	}
      }
    back:;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <list>
#include <set>
#include <string>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		list<char> List;
		set<char> Set;
		string str;
		cin >> str;
		List.push_back(str[0]);
		Set.insert(str[0]);
		for(int i = 2; i < str.size(); ++i)
		{
			if('a' <= str[i] && str[i] <= 'z')
			{
				if(!Set.count(str[i]))
				{
					if(str[i - 1] == '>')
					{
						List.push_back(str[i]);
					}
					else
					{
						List.push_front(str[i]);
					}
					Set.insert(str[i]);
				}
			}
		}
		for(list<char>::iterator Ite = List.begin(); Ite != List.end(); ++Ite)
		{
			cout << *Ite;
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int main(void){
  int n;
  cin>>n;
  while(n--){
    char data[2048]={'0'};
    char indata[2048];
    int max = 1024;
    int now = 1024;
    int min = 1024;
    cin>>indata;
    data[now]=indata[0];
    for(int i = 1; indata[i] != '\0'; i++){
      if(indata[i]=='>'){now++;max++;}
      else if(indata[i]=='<'){now--;min--;}
      else if(indata[i]=='-')continue;
      if(data[now]!='0')data[now]=indata[i];
    }
    for(int i = min; i <= max;i ++)
      cout<<data[i];
    cout<<endl;
  }
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
vector<int>g[26];
vector<int>ans;
bool used[26];
void dfs(int pos){
    if(used[pos])return;
    used[pos]=true;
    for(int i=0;i<g[pos].size();i++){
        dfs(g[pos][i]);
    }
    ans.push_back(pos);
}
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        fill_n(g,26,vector<int>(0));
        fill_n(used,26,false);
        ans.clear();
        char str[1025];
        scanf("%s",str);
        for(int i=1;str[i];i+=3){
            int v1=str[i-1]-'a';
            int v2=str[i+2]-'a';
            if(str[i]=='-'){
                g[v1].push_back(v2);
            }
            else{
                g[v2].push_back(v1);
            }
        }
        for(int i=0;i<26;i++){
            sort(g[i].begin(),g[i].end());
            g[i].erase(unique(g[i].begin(),g[i].end()),g[i].end());
        }
        for(int i=0;i<26;i++)if(g[i].size())dfs(i);
        reverse(ans.begin(),ans.end());
        for(int i=0;i<ans.size();i++){
            printf("%c",ans[i]+'a');
        }
        puts("");
    }

    return 0;
}

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


typedef long long ll;
const double Eps = 1e-5;

using namespace std;

int main()
{
	char buf[1024 + 256];
	cin.getline(buf, sizeof(buf));
	int n;
	sscanf(buf, "%d", &n);
	while (n--)
	{
		cin.getline(buf, sizeof(buf));
		strcat(buf, "--");
		pair<int, char> pos[26];
		for (int i = 0; i < 26; ++i)
		{
			pos[i].first = 9999;
			pos[i].second = i + 'a';
		}
		int relaPos = 0;
		for (int i = 0; buf[i] != '\0'; i += 3)
		{
			pos[buf[i] - 'a'].first = relaPos;
			if (buf[i + 2] == '>')
				++relaPos;
			else if (buf[i + 1] == '<')
				--relaPos;
		}
		sort(pos, pos+26);
		for (int i = 0; pos[i].first != 9999; ++i)
			putchar(pos[i].second);
		putchar('\n');
	}

	return 0;
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s,ans;
		cin >> s;
		ans = s[0];
		for (int j = 1; j < s.length(); j++) {
			if (isalpha(s[j])) {
				if (find(ans.begin(), ans.end(), s[j]) != ans.end())continue;

				if (s[j - 2] == '-'&&s[j - 1] == '>') {
					ans += s[j];
				}
				else if (s[j - 2] == '<'&&s[j - 1] == '-') {
					ans = s[j] + ans;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
using namespace std;
int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n;i++) {
		string buf;
		cin >> buf;
		int pos = 0;
		deque<char> list;
		list.push_back(buf[0]);
		for (auto it = buf.begin()+1; it < buf.end(); it += 3) {
			if (*it == '-')pos++;
			else pos--;
			if (pos == list.size())list.push_back(*(it + 2));
			else if (pos < 0) {
				pos = 0;
				list.push_front(*(it + 2));
			}
		}
		string s(list.begin(), list.end());
		cout << s << endl;
	}
	return 0;
}

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[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;
}