#include <bits/stdc++.h>
using namespace std;
const int M = 1000000 + 10;
const int N = 400000 + 10;
int t;
char s[N];
signed main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    int L = 0, R = 0, U = 0, D = 0;
    for (int i = 1; i <= len; ++i) {
      if (s[i] == 'L') L++;
      if (s[i] == 'R') R++;
      if (s[i] == 'U') U++;
      if (s[i] == 'D') D++;
    }
    int LR = 0, UD = 0;
    while (L && R) {
      LR++;
      L--, R--;
    }
    while (U && D) {
      UD++;
      U--, D--;
    }
    if (!LR && !UD) {
      printf("0\n\n");
      continue;
    }
    if (LR && UD) {
      printf("%d\n", (LR + UD) * 2);
      for (int i = 1; i <= LR; ++i) {
        printf("L");
      }
      for (int i = 1; i <= UD; ++i) {
        printf("U");
      }
      for (int i = 1; i <= LR; ++i) {
        printf("R");
      }
      for (int i = 1; i <= UD; ++i) {
        printf("D");
      }
      printf("\n");
      continue;
    }
    if (LR)
      printf("2\nLR\n");
    else
      printf("2\nUD\n");
  }
  return 0;
}
