#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	cin >> n;

	rep(i,n)
	{
		string s;
		cin >> s;

		vector<char> v;
		v.push_back(s[0]);
		int now = 0;

		rep(j,s.size())
		{
			if('a' <= s[j] && s[j] <= 'z')
			{
				int flag = 0;

				if(s[j+1] == '-' && s[j+2] == '>')
				{
					flag = 1;
				}
				else if(s[j+1] == '<' && s[j+2] == '-')
				{
					flag = 2;
				}

				if(flag == 1)
				{
					if('a' <= s[j+3] && s[j+3] <= 'z')
					{
						if(now == v.size() -1)
						{
							v.push_back(s[j+3]);
							now++;
						}
						else
						{
							now++;
						}
					}
				}
				else if(flag == 2)
				{
					if('a' <= s[j+3] && s[j+3] <= 'z')
					{
						if(now == 0)
						{
							vector<char> temp;
							std::copy(v.begin(),v.end(),std::back_inserter(temp));

							v[0] = s[j+3];
							v.resize(1);

							rep(h,temp.size())
							{
								v.push_back(temp[h]);
							}
						}
						else
						{
							now--;
						}
					}
				}
				else
				{
					break;
				}
			}

			if(j+3 == s.size()-1)
			{
				break;
			}
			else
			{
				j += 2;
			}
		}

		rep(j,v.size())
		{
			cout << v[j];
		}
		cout << endl;
	}
	return 0;
}