#include <bits/stdc++.h>
char s[200005];
int main() {
  long long n, t, i, j, k, x, y, z, u, d, l, r, min, min1;
  scanf("%lld", &t);
  for (i = 0; i < t; i++) {
    scanf("%s", s);
    l = 0;
    u = 0;
    r = 0;
    d = 0;
    x = 0;
    long long len = strlen(s);
    for (j = 0; j < len; j++) {
      if (s[j] == 'L') l = l + 1;
      if (s[j] == 'R') r = r + 1;
      if (s[j] == 'U') u = u + 1;
      if (s[j] == 'D') d = d + 1;
    }
    if (l != 0 && r == 0 && u == 0 && d == 0) {
      printf("0\n");
      x = 1;
    }
    if (l == 0 && r != 0 && u == 0 && d == 0) {
      printf("0\n");
      x = 1;
    }
    if (l == 0 && r == 0 && u != 0 && d == 0) {
      printf("0\n");
      x = 1;
    }
    if (l == 0 && r == 0 && u == 0 && d != 0) {
      printf("0\n");
      x = 1;
    }
    if (l != 0 && r != 0 && u == 0 && d == 0) {
      printf("2\n");
      printf("LR\n");
    }
    if (l != 0 && r == 0 && u != 0 && d == 0) {
      printf("0\n");
      x = 1;
    }
    if (l != 0 && r == 0 && u == 0 && d != 0) {
      printf("0\n");
      x = 1;
    }
    if (l == 0 && r != 0 && u != 0 && d == 0) {
      printf("0\n");
      x = 1;
    }
    if (l == 0 && r != 0 && u == 0 && d != 0) {
      printf("0\n");
      x = 1;
    }
    if (l == 0 && r == 0 && u != 0 && d != 0) {
      printf("2\n");
      printf("UD\n");
    }
    if (l != 0 && r != 0 && u != 0 && d == 0) {
      printf("2\n");
      printf("LR\n");
    }
    if (l == 0 && r != 0 && u != 0 && d != 0) {
      printf("2\n");
      printf("UD\n");
    }
    if (l != 0 && r == 0 && u != 0 && d != 0) {
      printf("2\n");
      printf("UD\n");
    }
    if (l != 0 && r != 0 && u == 0 && d != 0) {
      printf("2\n");
      printf("LR\n");
    }
    if (l != 0 && r != 0 && u != 0 && d != 0) {
      if (l <= r)
        min = l;
      else
        min = r;
      if (u <= d)
        min1 = u;
      else
        min1 = d;
      printf("%lld\n", 2 * (min + min1));
      for (j = 0; j < min; j++) printf("L");
      for (j = 0; j < min1; j++) printf("D");
      for (j = 0; j < min; j++) printf("R");
      for (j = 0; j < min1; j++) printf("U");
      printf("\n");
    }
    if (x == 1) printf(" \n");
  }
  return 0;
}
