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

int main(){
    int n,cnt;
    string s;
    cin >> n;
    while(n--){
        map <int,char> data;
        map <int,char>::iterator itr;
        cnt = 0;
        cin >> s;
        for(int i=0;i<s.length();i++){
            if(isalpha(s[i])){
                data.insert(map<int,char>::value_type(cnt,s[i]));
            }
            else if(s[i] == '<') cnt--;
            else if(s[i] == '>') cnt++;
        }
        for(itr=data.begin();itr!=data.end();itr++){
            cout << itr->second;
        }
        cout << endl;
    }
}