#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  string s;
  while (t--) {
    int u = 0, l = 0, r = 0, d = 0;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'L')
        l++;
      else if (s[i] == 'R')
        r++;
      else if (s[i] == 'U')
        u++;
      else
        d++;
    }
    if (l > r) l = r;
    if (r > l) r = l;
    if (d > u) d = u;
    if (u > d) u = d;
    if (l == 0 && u == 0) {
      cout << 0 << endl;
    } else {
      if (l == 0 && u > 1) {
        cout << 2 << endl << "UD" << endl;
      } else if (u == 0 && l > 1) {
        cout << 2 << endl << "RL" << endl;
      } else {
        cout << l + r + u + d << endl;
        for (int i = 0; i < r; i++) {
          cout << "R";
        }
        for (int i = 0; i < u; i++) {
          cout << "U";
        }
        for (int i = 0; i < l; i++) {
          cout << "L";
        }
        for (int i = 0; i < d; i++) {
          cout << "D";
        }
        cout << endl;
      }
    }
  }
  return 0;
}
