#include<iostream>
#include<deque>
#include<string>
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,n) loop(i,0,n)

using namespace std;

int main(){
    deque<char> d;
    string s;
    int n; cin >> n;
    rep(i,n){
        cin >> s;
        int p = 0, max = 0, min = 0;
        d.clear();
        d.push_back(s[0]);
        rep(k, s.size())if (k){
            if (s[k] == '-') p++;
            else p--;
            k += 2;
            if (p>max){
                d.push_back(s[k]);
                max = p;
            }
            else if (p<min){
                d.push_front(s[k]);
                min = p;
            }
        }

        rep(i, d.size()){
            cout << d[i];
        }
        cout << endl;
    }
}