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:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

map<string, int> rest;

int getRest(const string& s)
{
    int n = s.size();
    int i = 0;
    int t = 0;
    while(i < n){
        int j = i+1;
        while(j < n && s[j] != 'R')
            ++ j;
        t += rest[s.substr(i, j-i)];
        i = j;
    }
    return t;
}

int main()
{
    for(int i=1; i<=64; i*=2){
        int len = 64 / i;
        string s = "R";
        if(i >= 10)
            s += i / 10 + '0';
        s += i % 10 + '0';
        rest[s] = len;

        for(int j=i*2; j<=64; j*=2){
            len += 64 / j;
            s += '.';
            rest[s] = len;
        }
    }

    vector<string> dp(2001, "");
    for(int i=0; i<=2000; ++i){
        for(map<string, int>::iterator it=rest.begin(); it!=rest.end(); ++it){
            int j = i + it->second;
            if(j > 2000)
                continue;

            string s = dp[i] + it->first;
            if(dp[j] == "" || s.size() < dp[j].size() || (s.size() == dp[j].size() && s < dp[j]))
                dp[j] = s;
        }
    }

    int d;
    cin >> d;

    while(--d >= 0){
        string s;
        cin >> s;

        int t = getRest(s);
        if(t <= 2000){
            cout << dp[t] << endl;
            continue;
        }

        string ret = dp[1952+t%32].substr(0, 20);
        while(ret[ret.size()-1] != 'R')
            ret = ret.substr(0, ret.size()-1);
        ret = ret.substr(0, ret.size()-1);

        t -= getRest(ret);
        while(t > 2000){
            ret += "R1.";
            t -= 64 + 32;
        }
        ret += dp[t];
        cout << ret << endl;
    }

    return 0;
}