#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin.ignore();
  for(int i=0;i<n;i++){
    getline(cin,s);
    char c = s[0];
    char c1,c2,c3,c4;
    int j = 0;
    map<char,char> m;
    while(s[j+1]!='\0'){
      c1 = s[j];
      c2 = s[j+1];
      c3 = s[j+2];
      c4 = s[j+3];
      j += 3;
      if(c2=='<'){
	if(c==c1)
	  c = c4;
	m[c4] = c1;
      }
      else if(c3=='>')
	m[c1] = c4;
    }
    cout << c;
    while(m[c]!=0){
      cout << m[c];
      c = m[c];
    }
    cout << endl;
  }
  return 0;
}