#include <list>
#include <cstdio>

using namespace std;

int main(void){
    int n;
    char buf[1026], *p;
    list<char> trains;
    list<char>::iterator it;
    
    scanf("%d", &n);
    for (int i=0; i<n; i++){
        trains.clear();
        scanf("%s", buf);
        p = buf;
        trains.push_front(*p++);
        it = trains.begin();
        while (1){
  //          printf("(deb:%c)\n", *it);
            if (*p=='<'){
                p+=2;
                if (it==trains.begin()){
  //                  puts("deb:pf");
                    trains.push_front(*p);
                }
                p++;
                it--;
            }
            else if(*p=='-'){
                p+=2;
                it++;
                if (it==trains.end()){
  //                  puts("deb:pb");
                    it = trains.insert(it, *p);
                }
                p++;
            }
            else break;
        }
        for (it = trains.begin(); it!=trains.end(); it++){
            putchar(*it);
        }
        puts("");
    }
    return 0;
}