#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

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

int main()
{
    int n; cin >> n;
    int l;
    REP(n)
    {
        string s, ans, now = "0";
        cin >> s; l = (s.size())/3 + 1;
        //cout << "length = "<< l << endl;
        int pos = 0;
        now[0] = s[0];
        ans = now;
        rep(j,l - 1)
        {
            if(s[j*3+2] == '>') pos++;
            else pos--;
            now[0] = s[j*3 + 3];

            if(pos < 0){ ans = now + ans; pos++;}
            else if(pos == ans.size()){ ans = ans + now;}

        }
        cout << ans << endl;
    }

    return 0;
}