Problem: Music Macro Language (MML) is a language for textual representation of musical scores. Although there are various dialects of MML, all of them provide a set of commands to describe scores, such as commands for notes, rests, octaves, volumes, and so forth.

In this problem, we focus on rests, i.e. intervals of silence. Each rest command consists of a command specifier ‘R’ followed by a duration specifier. Each duration specifier is basically one of the following numbers: ‘1’, ‘2’, ‘4’, ‘8’, ‘16’, ‘32’, and ‘64’, where ‘1’ denotes a whole (1), ‘2’ a half (1/2), ‘4’ a quarter (1/4), ‘8’ an eighth (1/8), and so on. This number is called the base duration, and optionally followed by one or more dots. The first dot adds the duration by the half of the base duration. For example, ‘4.’ denotes the duration of ‘4’ (a quarter) plus ‘8’ (an eighth, i.e. the half of a quarter), or simply 1.5 times as long as ‘4’. In other words, ‘R4.’ is equivalent to ‘R4R8’. In case with two or more dots, each extra dot extends the duration by the half of the previous one. Thus ‘4..’ denotes the duration of ‘4’ plus ‘8’ plus ‘16’, ‘4...’ denotes the duration of ‘4’ plus ‘8’ plus ‘16’ plus ‘32’, and so on. The duration extended by dots cannot be shorter than ‘64’. For exapmle, neither ‘64.’ nor ‘16...’ will be accepted since both of the last dots indicate the half of ‘64’ (i.e. the duration of 1/128).

In this problem, you are required to write a program that finds the shortest expressions equivalent to given sequences of rest commands.



Input

The input consists of multiple datasets. The first line of the input contains the number of datasets N. Then, N datasets follow, each containing a sequence of valid rest commands in one line. You may assume that no sequence contains more than 100,000 characters.

Output

For each dataset, your program should output the shortest expression in one line. If there are multiple expressions of the shortest length, output the lexicographically smallest one.

Example

Input

3
R2R2
R1R2R4R8R16R32R64
R1R4R16


Output

R1
R1......
R16R1R4

Solution (in CPP):

Solution:
// 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;
	}
}