#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#include <list>
#include <set>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    while(n--)
    {
        string s; cin >> s;
        list<char> ls;
        set<char> st;
        ls.push_back(s[0]);
        st.insert(s[0]);
        for(int i = 1; i < s.size(); i += 3)
        {
            string t = s.substr(i, 2);
            if(st.count(s[i + 2])) continue;
            if(t == "->") ls.push_back(s[i + 2]);
            else ls.push_front(s[i + 2]);
            st.insert(s[i + 2]);
        }
        for(auto x : ls) cout << x;
        cout << endl;
    }
    return 0;
}


