#include<bits/stdc++.h>
using namespace std;

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        string s;
        cin >> s;
        deque<char> deq;
        set<char> st;
        bool back = false;
        for(int j=0;j<s.size();++j){
            if(s[j] == '<'){
                back = false;
                j++;
            }else if(s[j] == '-'){
                back = true;
                j++;
            }else{
                if(st.count(s[j]))continue;
                if(back)deq.push_back(s[j]);
                else deq.push_front(s[j]);
                st.insert(s[j]);
            }
        }
        for(auto c: deq){
            cout << c;
        }
        cout << endl;
    }

    return 0;
}

