#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);
const long long INFLL = (1ll << 60);
const long long MOD = (long long)(1e9 + 7);
void mul_mod(long long& a, long long b) {
  a *= b;
  a %= MOD;
}
void add_mod(long long& a, long long b) {
  a = (a < MOD) ? a : (a - MOD);
  b = (b < MOD) ? b : (b - MOD);
  a += b;
  a = (a < MOD) ? a : (a - MOD);
}
char s[100100];
int main(void) {
  int q, i, n, l, r, u, d, x, y;
  scanf("%d", &q);
  while (q--) {
    scanf("%s", s);
    n = strlen(s);
    l = 0;
    r = 0;
    u = 0;
    d = 0;
    for (i = 0; i < n; ++i) {
      switch (s[i]) {
        case 'L':
          ++l;
          break;
        case 'R':
          ++r;
          break;
        case 'U':
          ++u;
          break;
        case 'D':
          ++d;
          break;
      }
    }
    x = min(l, r);
    y = min(u, d);
    if (x && y) {
      printf("%d\n", (x + y) * 2);
      for (i = 0; i < x; ++i) {
        printf("R");
      }
      for (i = 0; i < y; ++i) {
        printf("D");
      }
      for (i = 0; i < x; ++i) {
        printf("L");
      }
      for (i = 0; i < y; ++i) {
        printf("U");
      }
    } else if (x) {
      printf("2\nLR");
    } else if (y) {
      printf("2\nUD");
    } else {
      printf("0\n");
    }
    printf("\n");
  }
  return 0;
}
