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<cstdio>
#include<cstring>
#include<cstring>
using namespace std;
int main(){
	
	int n;
	scanf("%d",&n);
	
	for(int q = 0;q < n; q++){
		
		char str[100] ={0};
		scanf("%s",str);
		
		char ans[30] ={0};
		
		ans[0] = str[0];
		
		bool check[128] = {0};
		
		check[str[0]] = 1;
		
		int x = 1;
		for(int i = 3; i < strlen(str); i+=3){
			
			if(check[str[i]] == 1)continue;
			check[str[i]] = 1;
			
			if(str[i-1] == '>'){
				ans[x] = str[i];
				x++;
			}
			else if(str[i-2] == '<'){
				for(int j = x;j > 0; j--)ans[j] = ans[j-1];
				ans[0] = str[i];
				x++;
			}
		}
		
		printf("%s\n",ans);
		
	}
	
	return 0;
}

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

using namespace std;

int main(void){
  int n;
  cin>>n;
  while(n--){
    char str[1000]={0};
    cin>>str;
    char ans[1000]={0};
    ans[0]=str[0];

    bool check[1280]={0};
    check[str[0]] = 1;

    int x = 1;
    for(int i = 3 ; i < strlen(str); i += 3){
	if(check[str[i]]== 1) continue;
	check[str[i]]=1;
	
	if(str[i-1]=='>'){
	  ans[x] =str[i];
	  x++;
	}
	else if(str[i-2] == '<'){
	  for(int j = x;j > 0; j--)ans[j] = ans[j-1];
	  ans[0] = str[i];
	  x++;
	}
      }
    
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
   int n;
   cin >>n;
 string s;
   cin >>s;
   for(int i=0;i<n;i++){
   int array[60];
    array[30]=s[0];
    int t=30;
   for(int i=0;i<s.length();i++){
   if(s[2+3*i]=='>'){
       t +=  1;
       array[t]=s[3*i+3];
   }else{
       t -= 1;
       array[t]=s[3*i+3];
   }
   }
   for(int i=0;i<60;i++){
       if(array[i]!=0){
           cout <<array[i];
       }
   }  
   cout <<endl;










   }
return 0;
}

C++: #include<iostream>
#include<deque>
using namespace std;
main()
{
	int t;cin>>t;
	for(;t--;)
	{
		string s;cin>>s;
		deque<char>a;
		a.push_back(s[0]);
		int d=0;
		for(int i=1;i<s.size();i+=3)
		{
			if(s.substr(i,2)=="->")
			{
				if(d+1>=a.size())
				{
					a.push_back(s[i+2]);
				}
				d+=1;
			}
			else
			{
				if(d==0)a.push_front(s[i+2]);
				else d-=1;
			}
		}
		for(int i=0;i<a.size();i++)cout<<a[i];
		cout<<endl;
	}
}

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

int main(){
  int n,c,i;
  for(cin>>n;n;n--){
    deque<char> d;
    string s;
    cin>>s;
    d.push_back(s[0]);
    for(i=1,c=0;i<s.size();i+=3){
      if(s[i]=='-')c++;
      else c--;
      if(c==d.size())d.push_back(s[i+2]);
      if(c==-1)d.push_front(s[i+2]),c=0;
    }
    for(i=0;i<d.size();i++)cout<<d[i];
    cout<<endl;
  }
}

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

using namespace std;

int main(int argc, char const* argv[])
{
	string input;
	char answer[64];
	int n;

	cin >> n;

	for( int i = 0;i < n;i++ ){
		cin >> input;
		for( int j = 0;j < 64;j++ ) answer[j] = '\0';
		int pos = 32;

		for( int j = 0;j < input.size() - 1;j += 3 ){
			answer[pos] = input[j];
			if( input[j + 1] == '<' ){
				pos--;
				answer[pos] = input[j + 3];
			} else if( input[j + 1] == '-' ){
				pos++;
				answer[pos] = input[j + 3];
			}
		}

		int j;
		for( j = 0;j < 64;j++ ){
			if( answer[j] != '\0' ) break;
		}

		cout << ( answer + j ) << endl;
	}
				

	return 0;
}

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

int n;
string s;
list<char> ls;

int main(){
	cin >> n;
	for(int I = 0; I < n; I++){
		cin >> s;
		ls = list<char>();
		ls.push_back(s[0]);
		list<char>::iterator itr = ls.begin();
		for(int i = 3; i < s.size(); i+=3){
			if(s[i-1] == '-'){
				if(itr == ls.begin()){
					ls.push_front(s[i]);
				}
				itr--;
			}
			else{

				if(++itr == ls.end()){
					ls.push_back(s[i]);
					itr = ls.end();
					itr--;
				}
			}
		}
		for(list<char>::iterator i = ls.begin(); i != ls.end(); i++){
			cout << *i;
		}
		cout << endl;
	}
	return 0;
}

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

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

	for (int a = 0;a < n;a++) {
		string s;
		string ans;
		cin >> s;

		ans = s[0];

		int b = s.size();
		for (int i = 0;i < b / 3;i++) {
			if (s[(i + 1) * 3 - 1] == '>') {
				size_t za = ans.find(s[(i + 1) * 3]);
				if (za == string::npos)ans += s[(i + 1) * 3];
			}
			else if (s[i * 3 + 1] == '<') {

				size_t zb = ans.find(s[(i + 1) * 3]);
				if (zb == string::npos) {
					string sb;
					sb= s[(i + 1) * 3];
					sb += ans;
					ans = sb;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  string str;
  map<int,char>data;
  int cnt;

  cin >> n;
  
  while(n--){
    cnt = 0;
    cin >> str;
    for(int i = 0;i < str.size();i++){
      if(isalpha(str[i]))data[cnt] = str[i];
      if(str[i] == '>')cnt++;
      if(str[i] == '<')cnt--;
    }

    for(map<int,char>::iterator it = data.begin();it != data.end();it++){
      cout << it->second;
    }
    cout << endl;
    data.clear();
  }
}

C++: #include <iostream>
#include <vector>
#include <string>
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;
}