#include <cstdint>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
stack<char> stk;
string str;
cin >> str;
for (auto& ch : str) {
if (stk.empty()) {
stk.push(ch);
} else if (stk.top() != ch) {
stk.push(ch);
} else {
stk.pop();
if (ch == 'o' && !stk.empty() && stk.top() == 'O') { // top 指的是pop后的top
stk.pop();
} else if (ch == 'o') {
stk.push('O');
}
}
}
// 1 两个'o'相遇:
// [o] + o → [] → [O]
// 2 两个'O'相遇:
// [O, O] → [O] → []
// 3 'O'和'o'相遇:
// [O] + o → [O, o]
// 4 特殊规则:
// [O, o] + o → [O] → [] (因为o + o = O,然后O + O = 爆炸)
string result;
while (!stk.empty()) {
result = stk.top() + result;
stk.pop();
}
cout << result << endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")