#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    string S;
    cin >> S;
    int n = S.size();
    int l = 0, r = 0, u = 0, d = 0;
    for (int i = 0; i < n; i++) {
      if (S[i] == 'L')
        l++;
      else if (S[i] == 'R')
        r++;
      else if (S[i] == 'U')
        u++;
      else
        d++;
    }
    int x = min(l, r);
    int y = min(u, d);
    if (y == 0) {
      if (x)
        printf("2\nLR\n");
      else
        printf("0\n");
    } else if (x == 0) {
      if (y)
        printf("2\nUD\n");
      else
        printf("0\n");
    } else {
      printf("%d\n", 2 * (x + y));
      for (int i = 1; i <= x; i++) printf("L");
      for (int i = 1; i <= y; i++) printf("U");
      for (int i = 1; i <= x; i++) printf("R");
      for (int i = 1; i <= y; i++) printf("D");
      printf("\n");
    }
  }
}
