#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>
#include <utility>

typedef long long Int;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
#define REPS(a,i,n) for(int i = a ; i < n ; ++i)
using namespace std;

string ans;

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

	char buff;

	REP(i, n){
		string chain;

		cin >> chain;

		auto it = chain.begin();

		ans = *(it++);

		while (it != chain.end()){
			string tmp(it, it + 2);
			it += 2;

			buff = *(it++);

			if (tmp == "->"){
				if (ans.find(buff) == string::npos)
					ans = ans + buff;
			}
			if (tmp == "<-"){
				if (ans.find(buff) == string::npos)
					ans = buff + ans;

			}

		}
		cout << ans << endl;
	}

	return 0;
}