#include <iostream>
#include <stack>
using namespace std;

string processBubbles(const string& input) {
    stack<char> st;
    
    for(char c : input) {
        while(true) {
            if(st.empty()) {
                st.push(c);
                break;
            }
            
            char top = st.top();
            if(c == 'o' && top == 'o') {
                st.pop();
                c = 'O';  // 转换但不立即处理
                continue;
            }
            else if(c == 'O' && top == 'O') {
                st.pop();
                break;  // 两个O抵消,不push
            }
            else {
                st.push(c);
                break;
            }
        }
    }
    
    string result;
    while(!st.empty()) {
        result = st.top() + result;
        st.pop();
    }
    return result;
}

int main() {
    int T;
    cin >> T;
    while(T--) {
        string s;
        cin >> s;
        cout << processBubbles(s) << endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")