#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(void) {
    int n, p;
    string d, r;

    for (cin >> n; n > 0; --n) {
        cin >> d;
        r = d[0];
        p = 0;
        for (int i = 1; i < d.length(); i += 3) {
            if (d.substr(i, 2) == "->") {
                try {
                    if (r.at(p+1) != d[i+2]) r = r + d[i+2];
                }
                catch(out_of_range&) {
                    r = r+d[i+2];
                }
                ++p;
            }
            else {
                try {
                    if (r.at(p-1) != d[i+2]) r = d[i+2] + r;
                }
                catch(out_of_range&) {
                    r = d[i+2] + r;
                }
                if (p > 0) --p;
            }
            cout << r << endl;
        }
        cout << r << endl;
    }
    return 0;
}