#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;
		int now = 0;
		string ans = string(1,s[0]);

		for(int i=1;i<s.size();i+=3){
			int alph = s[i+2];
			int dir = s[i+1]=='>'?R:L;

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