#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
//#include <map>
#include <iomanip>
#include <vector>

using namespace std;



string in;
int now, max_i, min_i;
char syaryo[1024];

void saiki(string in)
{
	string yajirusi;
	
	yajirusi = in.substr(0, 2);
	if (yajirusi == "") return;
	if (yajirusi == "->")
	{
		now++;
		max_i = max(now, max_i);
		syaryo[now] = in.substr(2, 1).c_str()[0];
		saiki(in.substr(3));
	} else {
		now--;
		min_i = min(now, min_i);
		syaryo[now] = in.substr(2, 1).c_str()[0];
		saiki(in.substr(3));
	}
}

int main()
{
	int n;
	
	cin >> n;
	for (int i=0; i<n; i++)
	{
		cin >> in;
		now = max_i = min_i = 512;
		syaryo[now] = in[0];
		saiki(in.substr(1));
		for (int j=min_i; j<=max_i; j++)
		{
			cout << syaryo[j];
		}
		cout << endl;
	}
	
	return 0;
}