#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;
}