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

int main(void)
{
	char vehi[1024][52 + 1];
	char *current;
	int n;
	char in[1025];
	
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++){
		int j;
		
		scanf("%s", in);
		current = vehi[i] + 26;
		memset(vehi[i], 0, 53 * sizeof(char));
		
		*current = in[0];
		j = 1;
		while (in[j] != '\0'){
			switch (in[j]){
				case '<':		 current--; break;
				case '>':		 current++; break;
				case '-':					break;
				default:  *current = in[j]; break;
			}
			j++;
		}
	}
	
	for (int i = 0; i < n; i++){
		int j;
		j = 0;
		while (vehi[i][j] == 0){
			j++;
		}
		while (vehi[i][j] != 0){
			printf("%c", vehi[i][j]);
			j++;
		}
		puts("");
	}
	
	return (0);
}