#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int sz = s.size();
    string ans(1, s[0]);
    char used[26] = {};
    used[s[0] - 'a'] = true;
    for (int j = 0; j + 3 < sz; j += 3) {
      if (used[s[j + 3] - 'a']) continue;
      used[s[j + 3] - 'a'] = true;
      if (s.substr(j + 1, 2) == "->") ans = ans + s[j + 3];
      else ans = s[j + 3] + ans;
    }
    cout << ans << endl;
  }

  return 0;
}
