#include <bits/stdc++.h>
using namespace std;
stack<char> stk;
int main() {
 int t;cin>>t;
 while(t--)
 {
 string s;cin>>s;
for(auto c:s)
{
    if(c=='o')
    {
        if(!stk.empty() && stk.top()=='o')
        {
            stk.pop();
            if(!stk.empty() && stk.top()=='O') stk.pop();
            else stk.push('O');
        }else stk.push(c);
    }
    else {
        if(!stk.empty() && stk.top()=='O') stk.pop();
        else stk.push(c);
    }
}
string res;
 while(!stk.empty())
 {
    res+=stk.top();
    stk.pop();
 }
 reverse(res.begin(),res.end());
 cout<<res<<endl;
 }
}
// 64 位输出请用 printf("%lld")