#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
char s[N];
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%s", s);
    int n = strlen(s);
    int l = 0, r = 0, u = 0, d = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'L') ++l;
      if (s[i] == 'R') ++r;
      if (s[i] == 'D') ++d;
      if (s[i] == 'U') ++u;
    }
    int min_x = min(l, r);
    int min_y = min(u, d);
    if (min_x == 0) {
      min_y = min(min_y, 1);
    }
    if (min_y == 0) {
      min_x = min(min_x, 1);
    }
    int len = min_x * 2 + min_y * 2;
    printf("%d\n", len);
    for (int i = 0; i < min_x; ++i) {
      putchar('L');
    }
    for (int i = 0; i < min_y; ++i) {
      putchar('U');
    }
    for (int i = 0; i < min_x; ++i) {
      putchar('R');
    }
    for (int i = 0; i < min_y; ++i) {
      putchar('D');
    }
    putchar('\n');
  }
}
