#include <iostream>
#include <map>
#include <string>

using namespace std;

typedef pair<char, char> Train;

int main()
{
    int n;
    cin >> n;
    while(n-- > 0) {
        string str;
        cin >> str;
        map<char, Train> vt;
        char a, b;
        for (int i = 1; i < str.size(); i += 3) {
            a = str[i - 1]; b = str[i + 2];
            string op = str.substr(i, 2);
            if(vt.find(a) == vt.end()) {
                vt[a] = Train(' ', ' ');
            }

            if (vt.find(b) == vt.end()) {
                vt[b] = Train(' ', ' ');
            }

            if (op == "->") {
                vt[a].second = b;
                vt[b].first = a;
            } else {
                vt[b].second = a;
                vt[a].first = b;
            }
        }

        while (vt[a].first != ' ')
            a = vt[a].first;
        
        while (true) {
            cout << a;
            a = vt[a].second;
            if (vt[a].second == ' ') {
                cout << a;
                break;
            }
        }
        cout << endl;
    }
}