#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int nex[26];
bool app[26],aft[26];
int main(){
	int n;
	cin>>n;
	for(int u=0;u<n;u++){
	string s;
	cin>>s;
	for(int i=0;i<26;i++)app[i]=false,nex[i]=114514,aft[i]=false;
	for(int i=0;i<s.size();i++){
		if(s[i]>='a'&&s[i]<='z')app[s[i]-'a']=true;
	}
	for(int i=0;i<s.size()-1;i+=3){
		if(s[i+1]=='-'){
			nex[s[i]-'a']=s[i+3]-'a';
			aft[s[i+3]-'a']=true;
		}
		else{
			nex[s[i+3]-'a']=s[i]-'a';
			aft[s[i]-'a']=true;
		}
	}
	int t=0;
	while(true){
		if(app[t]&&!aft[t])break;
		t++;
	}
	while(true){
		char z=t+'a';
		cout<<z;
		t=nex[t];
		if(t==114514)break;
	}
	cout<<endl;
	}
	return 0;
}