#include <cstdio>
#include <list>
using namespace std;
int main(){
	typedef list<char> lc;
	int n;
	char c,d;
	for(scanf("%d ",&n);n--;scanf(" ")){
		lc ls;
		ls.push_back(getchar());
		lc::iterator it=ls.begin();
		for(;d=getchar(),d=='-'||d=='<';){
			getchar();
			c=getchar();
			if(d=='-'){
				if(++it==ls.end())it=ls.insert(it,c);
			}else{
				if(it==ls.begin())it=ls.insert(it,c);
				else --it;
			}
		}
		for(it=ls.begin();it!=ls.end();++it)putchar(*it);
		puts("");
	}
}