#include<iostream>
#include<list>
#include<string>
using namespace std;int main(){int i;string s;list<char> l;list<char>::iterator x;getline(cin,s);while(getline(cin,s)){l.clear();l.push_back(s[i=0]);x=l.begin();while(++i<s.size()){if(s[i++]=='<'&&*--x!=s[++i]){l.insert(++x,s[i]);x--;}if(s[i]=='>'&&*++x!=s[++i]){l.insert(x,s[i]);x--;}}for(x=l.begin();x!=l.end();)cout<<*x++;cout<<endl;}return 0;}