#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)
typedef long long ll;

using namespace std;

int main(void){

int n;
string s;

	while(cin >> n){
		if(cin.eof()) break;
		rep(i,n){
			cin >> s;
			int dt;
			string ans="";
			rep(j,s.size()){
				if(s[j] >= 'a' && s[j] <= 'z' ){
					if(ans=="") ans = s[j];
					bool fn=true;
					rep(k, ans.size()) if(s[j]==ans[k]) fn=false;
					if(fn && dt<0 ) ans = s[j] + ans;
					if(fn && dt>0 ) ans = ans  + s[j];

				}
				if(s[j] >= '<') dt=-1;
				if(s[j] >= '>') dt= 1;

			}
		cout << ans << endl;
		}
	}
	return 0;
	
}