#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
string zifuchuan;
cin >> zifuchuan;
if (zifuchuan.empty()) {
cout << endl;
continue;
}
stack<char> zhan;
zhan.push(zifuchuan[0]);
for (int i = 1; i < zifuchuan.size(); i++) {
char current = zifuchuan[i];
if (zhan.empty()) {
zhan.push(current);
continue;
}
char top = zhan.top();
if (current == 'O' && top == 'O') {
// 两个大泡泡爆炸
zhan.pop();
} else if (current == 'o' && top == 'o') {
// 两个小泡泡融合成大泡泡
zhan.pop();
zhan.push('O');
// 检查新产生的大泡泡是否引发连锁反应
if (zhan.size() >= 2) {
char new_top = zhan.top(); // 新产生的'O'
zhan.pop();
char next_top = zhan.top(); // 原来的栈顶
if (new_top == 'O' && next_top == 'O') {
// 新产生的大泡泡和原来的大泡泡爆炸
zhan.pop();
} else {
zhan.push(new_top);
}
}
} else {
zhan.push(current);
}
}
// 正确地从栈中提取结果
vector<char> result;
while (!zhan.empty()) {
result.push_back(zhan.top());
zhan.pop();
}
// 反转结果(因为栈是后进先出)
for (int i = result.size() - 1; i >= 0; i--) {
cout << result[i];
}
cout << endl;
}
return 0;
}