#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second


main(){
  int n;
  cin>>n;
  while(n--){
    string in,ans;
    cin>>in;
    int pos=0;
    rep(i,in.size()){
      if(isalpha(in[i])){
        ans+=in[i];
        pos=0;
      }else if(in[i]=='-')continue;
      else if(in[i]=='<'){
        i+=2;
        pos--;
        if(pos<0)ans=in[i]+ans,pos=0;
      }else{
        i++;
        pos++;
        if(pos>=ans.size())ans+=in[i];
      }
    }
    cout<<ans<<endl;
  }
}