#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        vector<int> post(30,-1),pre(30);
        string s;
        cin >> s;
        if(s.size() < 3){
            cout << s << endl;
        }else{
            for(int j = 3; j < s.size(); j += 3){
                int now = s[j] - 'a';
                int bef = s[j-3] - 'a';
                if(s[j-2] == '<')swap(now,bef);
                post[bef] = now;
                pre[now]++;
            }
            for(int j = 0; j < 30; j++){
                if(pre[j] == 0 && post[j] != -1){
                    int now = j;
                    cout << char('a' + now);
                    while(post[now] != -1){
                        now = post[now];
                        cout << char('a' + now);
                    }
                    cout << endl;
                }
            }
        }
    }
}

