#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VII;
typedef pair<int, int> PII;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back;
#define MP make_pair
#define SIZE(a) int((a).size())
#define SORT(c) sort((c).begin(), (c).end())

const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 3;

int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

string solve(string &input){
  string train(input, 0, 1);
  int f = 0, b = 0, n = 0;
  for(int i = 1; i < input.size(); i++){
    if(input[i] == '<') n++;
    else if(input[i] == '>') n--;
    else if(input[i] != '-' && n > f) { train.insert(train.begin(), input[i]); f = n;}
    else if(input[i] != '-' && n < b) { train.insert(train.end(), input[i]); b = n;}
  }
  return train;
}

int main(void){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    string input;
    cin >> input;
    cout << solve(input) << endl;
  }
  return 0;
}