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

#define LINEMAX 1025
char train[60];

typedef struct _two {
	int head;
	int tail;
} TWO_T;

TWO_T maketrain( char str[LINEMAX] )
{
	int medium_stat = 30;
	TWO_T tval;
	tval.head = 30; tval.tail = 30;
	char *p; p = str;

	// 一番最初の文字列が列車の最初の車両としてスタート, 
	// 左・右に進むにつれて列車の構成を変更していく
	while ( *p ) {
		if ( isalpha( *p ) ) {
			train[medium_stat] = *p;
			p++;
		} else { 
			if ( *p == '-' ) {
				medium_stat++;
				if ( medium_stat > tval.tail ) {
					tval.tail = medium_stat;
				}
			} else if ( *p == '<' ) {
				medium_stat--;
				if ( medium_stat < tval.head ) {
					tval.head = medium_stat;
				}
			}
			p += 2;
		}
	}
	return tval;
}


int main()
{
	char str[LINEMAX];
	int num, midium_stat = 30;
	TWO_T tval;

	scanf( "%d", &num );

	for ( int i = 0 ; i < num ; i++ ) {
		memset( train, '0', sizeof( train ) );
		scanf( "%s", str );
		tval = maketrain( str );
		for ( int j = tval.head ; j <= tval.tail ; j++ ) {
			printf( "%c", train[j] );
		}
		printf( "\n" );
	}
	return 0;
}

