https://www.acmicpc.net/problem/5397
#include <bits/stdc++.h>
using namespace std;
int n;
list<char> link_l;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("input.txt", "rt", stdin);
cin >> n;
for (int i = 1; i <= n; i++) {
string in;
cin >> in;
auto it = link_l.begin();
for (auto ch: in) {
if (ch == '<') {
if (it != link_l.begin()) it--;
}
else if (ch == '>') {
if (it != link_l.end()) it++;
}
else if (ch == '-') {
if (it != link_l.begin()) {
auto temp = it;
temp--;
link_l.erase(temp);
}
}
else {
link_l.insert(it, ch);
}
}
for (auto ch : link_l) {
cout << ch;
}
cout << '\n';
link_l.clear();
}
return 0;
}