// Problem E : Optimal Rest

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(){
	// x\»ðÅãÉRðÁ¦½êÌ«ÅSÊèðÀ×½àÌ
	string str[] = {"R1......", "R1.....", "R1....", "R1...", "R1..", "R1.", "R16..", "R16.", "R16", "R1", 
				    "R2....." , "R2...." , "R2...", "R2..", "R2.", "R2", "R32.", "R32",
			    	"R4....", "R4...", "R4..", "R4.", "R4", "R64", "R8...", "R8..", "R8.", "R8" };
	// ãÌÅx\»Ì·³ð«ºµ½àÌ
	int back[] = {127, 126, 124, 120, 112, 96, 7, 6, 4, 64, 63, 62, 60, 56, 48, 32, 3, 2, 31, 30, 28, 24, 16, 1, 15, 14, 12, 8};
	static int len[3200001]; len[0] = 0;
	for(int i=1;i<=3200000;i++){
		len[i] = len[i-1]+3;
		for(int j=0;j<28;j++){
			if(i-back[j] < 0) continue;
			len[i] = min(len[i], len[i-back[j]] + (int)str[j].size());
		}
	}
	int test; cin >> test;
	string s;
	while(test--){
		cin >> s;
		// üÍ¶ñª\»·éxÌ·³ð²×é
		for(int i=0;i<s.size();i++) if(s[i]=='R') s[i] = ' ';
		istringstream iss(s);
		string tmp;
		int lest = 0;
		while(iss >> tmp){
			tmp = "R"+tmp;
			for(int i=0;i<28;i++)
				if(tmp == str[i]) lest += back[i];
		}
		while(lest > 0){
			for(int i=0;i<28;i++){
				if(lest-back[i] < 0) continue;
				if(len[lest] == len[lest-back[i]] + str[i].size()){
					cout << str[i];
					lest -= back[i];
					break;
				}
			}
		}
		cout << endl;
	}
}