#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
int u, d, l, r;
char mve[MAX_N];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    u = d = l = r = 0;
    scanf("%s", mve);
    int len = strlen(mve);
    for (register int i = 0; i <= len - 1; i++) {
      if (mve[i] == 'U')
        u++;
      else if (mve[i] == 'D')
        d++;
      else if (mve[i] == 'L')
        l++;
      else
        r++;
    }
    int m1 = 0, m2 = 0;
    m1 = min(u, d), m2 = min(l, r);
    if (m1 && m2) {
      printf("%d\n", 2 * (m1 + m2));
      for (register int i = 1; i <= m2; i++) printf("L");
      for (register int i = 1; i <= m1; i++) printf("U");
      for (register int i = 1; i <= m2; i++) printf("R");
      for (register int i = 1; i <= m1; i++) printf("D");
    } else if (m1 && !m2)
      printf("2\nUD");
    else if (!m1 && m2)
      printf("2\nLR");
    else
      printf("0\n");
    putchar(10);
  }
  return 0;
}
