#include <iostream>
#include <algorithm>
#include <string>
#include <deque>
using namespace std;

int main() {
    int T; cin >> T;
    cin.ignore();

    while(T--) {
        string line;
        getline(cin, line);
        line += "@";

        deque<char> Q;
        int cur = 0;
        int front = 0;
        int back = 0;
        int p = 0;

        Q.push_back(line[0]);
        p++;

        while(true) {
            if(line[p] == '@') break;

            if(line[p] == '<') {
                cur--;
                p += 2;

                if(!(front <= cur && cur <= back)) {
                    Q.push_front(line[p]);
                    front = cur;
                }

                p++;
            }
            else {
                cur++;
                p += 2;

                if(!(front <= cur && cur <= back)) {
                    Q.push_back(line[p]);
                    back = cur;
                }

                p++;
            }
        }

        while(!Q.empty()) {
            cout << Q.front();
            Q.pop_front();
        }
        cout << endl;
    }
}