#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string train;
string str;
void calc(){
	train=str[0];
	map<char,int> data;
	data.clear();
	data[str[0]]++;
	for(int i =0;i <str.length();){
		if(isalpha(str[i])){
			string tmp =str.substr(i+1,2);
			i+=3;
			if(tmp=="->"){
				if(data[str[i]])continue;
				train =train+str[i];
				data[str[i]]++;
			}else{
				if(data[str[i]])continue;
				train =str[i]+train;
				data[str[i]]++;
			}
		}
	}
}


int main(){
	int n;
	cin>>n;
	cin.ignore();
	rep(i, n){
		getline(cin, str);
		calc();
		cout <<train<<endl;
	}
	return 0;
}