#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n;
    string str;
    cin >> n;
    rep(i, n)
    {
        char c[100] = {0};
        cin >> str;
        int index = 30;
        int move = 0;
        rep(j, str.size())
        {
            if ((int)(str[j] - 'a') >= 0 && (int)(str[j] - 'z') <= 0)
            {
                c[index] = str[j];
            }
            else if (str[j] == '<')
            {
                move = -1;
                index += move;
            }
            else if (str[j] == '>')
            {
                move = 1;
                index += move;
            }
            else
            {
                continue;
            }
        }
        rep(j, 100)
        {
            if (c[j] != 0)
                cout << c[j];
        }
        cout << endl;
    }
    return 0;
}
