#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;

int main(void){
	int i,n,now,from,to;
	char c,rst[64];

	cin>>n;
	getchar();
	while(n--){
		now = from = to = 26;
		while((c=getchar()) != '\n'){
			if(isalpha(c)) rst[now] = c;
			else{
				if((c=getchar()) == '>'){
					now++;
					if(now > to) to++;
				}
				else{
					now--;
					if(now < from) from--;
				}
			}
		}
		for(i=from;i<=to;i++) cout<<rst[i];
		cout<<endl;
	}

	return 0;
}