#include <bits/stdc++.h>
using namespace std;
inline void swap(long& x, long& y) {
  int m = x;
  x = y;
  y = m;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int L = 0, R = 0, U = 0, D = 0;
    int j = 0;
    while (s[j] != '\0') {
      switch (s[j]) {
        case 'L':
          L++;
          j++;
          break;
        case 'R':
          R++;
          j++;
          break;
        case 'U':
          U++;
          j++;
          break;
        case 'D':
          D++;
          j++;
          break;
        default:
          break;
      }
    }
    if (L > R)
      L = R;
    else
      R = L;
    if (U > D)
      U = D;
    else
      D = U;
    if (L == 0 && D == 0) {
      cout << 0 << endl;
      continue;
    }
    if (L == 0) {
      cout << 2 << endl;
      cout << "UD" << endl;
      continue;
    }
    if (U == 0) {
      cout << 2 << endl;
      cout << "RL" << endl;
      continue;
    }
    int sum = L + R + D + U;
    cout << sum << endl;
    for (int i = 0; i < sum; i++) {
      if (i < L - 1)
        cout << "L";
      else if (i < L + D - 1)
        cout << "D";
      else if (i < L + D + R - 1)
        cout << "R";
      else if (i < L + D + R + U - 1)
        cout << "U";
      else if (i == sum - 1)
        cout << "L" << endl;
    }
  }
  return 0;
}
