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

int main() {
    int n;
    cin >> n;
    cin.ignore();
    while (n--) {
        string line;
        getline(cin, line);
        string trainCars = "";
        trainCars += line[0];
        line.erase(0, 1);
        int i = 0;
        while (line.empty() == false) {
            if (line.substr(0, 2) == "->") {
                i++;
            } else {
                i--;
            }
            line.erase(0, 2);
            if (i == -1) {
                trainCars.insert(0, 1, line[0]);
                i = 0;
            } else if (i == (int) trainCars.length()) {
                trainCars += line[0];
            }
            line.erase(0, 1);
        }
        cout << trainCars << endl;
    }
}