#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <climits>
#include <cfloat>
#include <queue>
#include <stack>

using namespace std;


#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define INF  INT_MAX

typedef long long LL;
typedef pair<int,int> P;
typedef vector<int,int> vii;


int main(){
    int n;cin>>n;
    while(n--){
        string s;cin>>s;
        char ans[2000];
        rep(i,2000) ans[i]='0';
        int now=1000;
        int start=1000,last=1000;
        //cout << s.length() << endl;
        for(int i=0;i<s.length();i+=3){
            //cout << i << endl;
            if(s[i]=='\n') break;
            ans[now]=s[i];
            if(s[i+2]=='>'){
                now++;
                if(now>last){
                    last=now;
                }
            }else if(s[i+1]=='<'){
                now--;
                if(start>now){
                    start=now;
                }
            }
        }
        //cout << start << endl;
        //cout << last << endl;
        for(int i=start;i<=last;i++){
            cout << ans[i];
        }
        cout << endl;
    }
    return 0;
}