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 <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 64*100100;
const int inf = 1e9;

char s[MAX];
int f[MAX];
int nx[MAX], nr[MAX], ns[MAX];


int main(void) {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s);
    int len = strlen(s);
    int i = 0;
    int last = 0;
    int sum = 0;
    while (i < len) {
      if (s[i] == '.') {
        last /= 2;
        i++;
      } else {
        assert(s[i] == 'R');
        i++;
        int x = 0;
        while (i < len && isdigit(s[i])) x = x*10 + s[i++] - '0';
        last = 64 / x;
      }
      sum += last;
    }

    f[0] = 0;
    nx[0] = -1;
    FOR(s, 1, sum + 1) {
      f[s] = inf;
      auto test = [&] (int x, int d) {
        int len = 1 + 1 + (x >= 10) + d, tmp = x;
        int total = 64 / x;
        REP(i, d) total += 64 / (tmp *= 2);
        if (total > s) return;
        if (len + f[s - total] < f[s]) {
          f[s] = len + f[s - total];
          nx[s] = x, nr[s] = d, ns[s] = s - total;
        }
      };

      FOR(i, 1, 7) test(1, 7-i);
      REP(i, 7) test(16, 6-i);
      test(1, 0);
      for (int x: {2, 32, 4, 64, 8}) REP(i, 7) test(x, 6-i);
    }
  
    while (sum > 0) {
      putchar('R');
      printf("%d", nx[sum]);
      REP(i, nr[sum]) putchar('.');
      sum = ns[sum];
    }
    putchar('\n');
  }
  return 0;
}