#include <stdio.h>
#include <string.h>

// int search(char[], char, int);
// void swap(char[], int, int);
void pre_connect(char[], char, int);

int main (){
    int n, i, j, count, idx;
    char str[1024], line[60], train;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%s",str);

        line[0] = str[0];
        count = 1;
        idx=0;
        for(j=2; j<strlen(str); j+=3){
            if(str[j] == '>'){
                if(line[idx+1] == str[j+1]){
                    idx++;
                } else {
                    line[count++] = str[j+1];
                    idx++;
                }
            } else {
                if(line[idx-1] == str[j+1]){
                    idx--;
                } else {
                    pre_connect(line, str[j+1], count);
                    count++;
                }
            }
        }
        line[count] = '\0';
        printf("%s\n", line);
    }
    return 0;
}

/* 
int search(char line[], char t, int count){
    int i;

    for(i=0; i<count; i++){
        if(line[i] == t){
            return i;
        }
    }
    return -1;
}

void swap(char line[], int i, int j){
    char tmp;
    tmp = line[i];
    line[i] = line[j];
    line[j] = tmp;
}
*/

void pre_connect(char line[], char t, int count){
    int i;
    char new[60];

    new[0] = t;

    for(i=1; i<=count; i++){
        new[i] = line[i-1];
    }
    new[i] = '\0';

    strcpy(line, new);
}