#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define R 1
#define L -1


int main(){
	int n;
	cin>>n;
	rep(loop,n){
		string s;
		cin>>s;
		string ans = string(1,s[0]);
		int now=0;
		for(int i=1;i<s.size();i+=3){
			int alph = s[i+2];
			int dir;
			if(s[i+1]=='>'){dir = R;now++;}
			else {dir = L;now--;}

			if( now==-1){
				now = 0;
				if(dir == R)ans=ans+string(1,alph);
				else ans = string(1,alph)+ans;
			}else if(now==ans.size()){
				now = now--;
				if(dir == R)ans=ans+string(1,alph);
				else ans = string(1,alph)+ans;
			}
		}
		cout<<ans<<endl;
	}
}