#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n,p,check;
    char s[1024];
    while(cin >> n){
        rep(j,n){
            p = 350;
            check = 0;
            char ans[700] = {'0'};
            cin >> s;
            for(int i = 0; s[i]; i++){
                if(s[i] >= 'a' && s[i] <= 'z'){
                    ans[p] = s[i];
                }else if(s[i] == '>'){
                    p++;
                }else if(s[i] == '<'){
                    p--;
                }
            }
            rep(i,700){
                if(ans[i] == '0'){
                    continue;
                }else if(ans[i] >= 'a' && ans[i] <= 'z'){
                    cout << ans[i];
                }
            }cout << endl;
        }
    }
}