#include <cstdio>
#include <cstdlib>
#include <cstring>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
char buf[1025], res[128], mem[26], *p;
int n, l, r, h, t;
int main()
{
    n = atoi(fgets(buf, 1025, stdin));
    while (n--) {
        memset(res, 0, sizeof(res));
        memset(mem, 0, sizeof(mem));
        fgets(buf, 1025, stdin);
        p = &buf[strlen(buf)-1];
        if (*p == '\n') *p = '\0';

        h = t = 0;
        l = sizeof(res) / 2 - 1;
        r = sizeof(res) / 2 + 1;
        res[sizeof(res) / 2] = buf[0];
        mem[buf[0]-'a'] = 1;
        REP(i, 1, strlen(buf)) {
            if (buf[i] == '-') continue;
            else if (buf[i] == '<') { h = 1; t = 0; }
            else if (buf[i] == '>') { h = 0; t = 1; }
            else {
                if (mem[buf[i]-'a']) continue;
                mem[buf[i]-'a'] = 1;
                if (h) res[l--] = buf[i];
                else if (t) res[r++] = buf[i];
            }
        }
        rep(i, sizeof(res)) if (res[i] > 0) putchar(res[i]);
        puts("");
    }
    return 0;
}