#include<bits/stdc++.h>

using namespace std;

int main(){

  int n;

  cin >> n;

  vector<string> junkai(n);
  
  for(int i = 0;i < n;++i){
	cin >> junkai[i];

	string train;
	int point = 0;
	
	train = junkai[i][0];
	
	for(int j = 1;j < junkai[i].size();j+=3){
	  if(junkai[i][j] == '-' && junkai[i][j+1] == '>'){
		if(train[point + 1] == '\0'){
		  train += junkai[i][j+2];
		}
		point++;
	  }
		
	  else if(junkai[i][j] == '<' && junkai[i][j+1] == '-'){
		if(point == 0)
		  train = junkai[i][j+2] + train;
		else
		  point--;
	  }
	}
	cout << train << endl;
  }
}

