#include<bits/stdc++.h>
using namespace std;

int T;
string s;

int main(){
	cin>>T;
	
	while(T--){
		cin>>s;
		stack<char> st;
		for(int i=0;i<s.size();i++){
			if(s[i]=='o'&&(st.empty()||!st.empty()&&st.top()!='o')){
				st.push('o');
			}else if(s[i]=='o'&&!st.empty()&&st.top()=='o'){
				st.pop();
				if(!st.empty()&&st.top()=='O'){
					st.pop();
				}else{
					st.push('O');
				}
			}else if(s[i]=='O'&&(st.empty()||!st.empty()&&st.top()!='O')){
				st.push('O');
			}else if(s[i]=='O'&&!st.empty()&&st.top()=='O'){
				st.pop();
			}
		}
		string res="";
		while(!st.empty()){
			res=st.top()+res;
			st.pop();
		}
		cout<<res<<endl;
	}
	
    return 0;
}