#define scanf_s scanf
#include <stdio.h>
#include<iostream>
#include <deque>
using namespace std;
#define MAX 1025
int main()
{
	int n;
	char str[MAX];
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		int now = 0;
		deque<char> qu;
		scanf_s("%s", str, MAX);
		for (int j = 0; str[j] != '\0'; ++j) {
			if ('a' <= str[j] && str[j] <= 'z') {
				if (qu.empty() || now  == (int)qu.size()) {
					qu.push_back(str[j]);
				}
				else if(now == -1){
					qu.push_front(str[j]);
					++now;
				}
			}
			if (str[j] == '>') { ++now; }
			else if (str[j] == '<') { --now; }
		}
		for (int k = 0; k < (int)qu.size(); ++k) {
			printf("%c", qu[k]);
		}
		printf("\n");
	}
}