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

int c (string str, int dir, int cursor, char a) {
    for (int i = cursor; 0 <= i && i < str.size(); i += dir) {
        if (a == str[i]) {
            return i;
        }
    }

    return cursor + dir;
}

int main ()
{
    string str;
    int n;
    cin >> n;
    while (n--) {
        cin >> str;
        int cursor = 0;
        string res = "";

        res += str[0];

        for (int i = 1; i < str.size()-2; i += 3) {
            if (str[i] == '-') {
                cursor = c(res, 1, cursor, str[i+2]);
                if (res.size() == cursor) {
                    res += str[i+2];
                }
            } else if (str[i] == '<') {
                cursor--;
                cursor = c(res, -1, cursor, str[i+2]);
                if (cursor < 0) {
                    res = str[i+2] + res;
                    cursor = 0;
                }
            }
        }

        cout << res << endl;
    }

    return 0;
}