#include <iostream>
#include <string>
#include <list>
#include <map>
using namespace std;

#define repeat(n, i) for(int i = 0; i < (n); i++)

int main() {
    int n; cin >> n;
    repeat(n, i) {
        string s; cin >> s;
        list<char> train;
        bool which = false; // right: false, left: true
        map<char, bool> used;
        for (string::iterator si = s.begin(); si != s.end(); si++) {
            if (*si == '-') continue;
            if (*si == '<') {
                which = true;
            } else if (*si == '>') {
                which = false;
            } else if (!used[*si]) {
                used[*si] = true;
                if (which) {
                    train.push_front(*si);
                } else {
                    train.push_back(*si);
                }
            }
        }
        for (list<char>::iterator li = train.begin(); li != train.end(); li++) {
            cout << *li;
        }
        cout << endl;
    }
    return 0;
}
            
                    