#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		char str[2048];
		scanf("%s", str);
		deque<int> train;
		int pos = 0;
		train.push_front(str[0]);
		reep(i, 1, strlen(str)){
			if(str[i+1] == '>')
				++pos;
			else
				--pos;
			i += 2;
			if(pos < 0){
				train.push_front(str[i]);
				pos = 0;
			}else if(train.size() <= pos){
				train.push_back(str[i]);
			}
		}
		
		rep(i, train.size())
			putchar(train[i]);
		puts("");
	}
	return 0;
}