#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	while(n--){
		string s="";
		string in;
		cin>>in;
		s+=in[0];
		int q=0;
		int qq=1;
		while(in.size()!=qq){
			if(in[qq]=='<'){
				qq+=2;
				if(q)q--;
				else s.insert(s.begin(),in[qq]);
			}else{
				qq+=2;
				if(q!=s.size()-1)q++;
				else {s+=in[qq];q++;}
			}
			qq++;
		}
		cout<<s<<endl;
	}
}