#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){

  int n;
  cin>> n;
  while(n--){
    int cnt=0;
    string s;
    map<int,char> m;
    cin>> s;
    for(int i=0;i<s.size();i++){
      if(isalpha(s[i])) m[cnt]=s[i];
      else if(s[i]=='<') cnt--;
      else if(s[i]=='>') cnt++;
    }

    for(map<int,char>::iterator it=m.begin();it!=m.end();it++){
      cout<< (*it).second;
    }

    cout<< endl;
  }
}