#include <iostream>
#include <string>

using namespace std;

int n;
string str;

int main()
{
    cin >> n;
    while (n-- > 0) {
        cin >> str;
        int len = str.size();
        char t[26][2]; // front back
        for (int i = 0; i < 26; i++)
            t[i][0] = t[i][1] = -1;

        for (int i = 3; i < len; i+= 3) {
            int a = str[i - 3] - 'a', b = str[i] - 'a';
            if (str.substr(i - 2, 2) == "->") {
                t[a][1] = b;
                t[b][0] = a;
            } else {
                t[a][0] = b;
                t[b][1] = a;
            }
        }

        int s = -1;
        for (int i = 0; i < 26; i++) {
            if (t[i][0] == -1 && t[i][1] != -1) {
                s = i;
                break;
            }
        }

        do {
            printf("%c", s + 'a');
            s = t[s][1];
        } while (s != -1); 
        
        if (n != 1) 
            cout << endl;
    }    
}