#include <bits/stdc++.h>
using namespace std;
int T;
char a[100005];
int main() {
  scanf("%d", &T);
  while (T--) {
    int l = 0, r = 0, u = 0, d = 0;
    scanf("%s", a + 1);
    for (int i = 1; i <= strlen(a + 1); i++) {
      if (a[i] == 'L') l++;
      if (a[i] == 'R') r++;
      if (a[i] == 'U') u++;
      if (a[i] == 'D') d++;
    }
    int p1 = min(l, r), p2 = min(u, d);
    if (p1 == 0 && p2 == 0) {
      printf("0\n");
      printf("\n");
    } else if (p1 == 0) {
      printf("2\n");
      printf("UD\n");
    } else if (p2 == 0) {
      printf("2\n");
      printf("LR\n");
    } else {
      printf("%d\n", p1 * 2 + p2 * 2);
      for (int i = 1; i <= p1; i++) printf("L");
      for (int i = 1; i <= p2; i++) printf("U");
      for (int i = 1; i <= p1; i++) printf("R");
      for (int i = 1; i <= p2; i++) printf("D");
      printf("\n");
    }
  }
  return 0;
}
