#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long left = 0;
    long long right = 0;
    long long up = 0;
    long long down = 0;
    for (long long i = 0; i < s.size(); i++) {
      if (s[i] == 'L')
        left++;
      else if (s[i] == 'R')
        right++;
      else if (s[i] == 'U')
        up++;
      else if (s[i] == 'D')
        down++;
    }
    if (left != 0 && right != 0 && up != 0 && down != 0) {
      long long minHor = min(left, right);
      long long minVer = min(up, down);
      cout << 2 * minHor + 2 * minVer << endl;
      for (long long i = 0; i < minHor; i++) cout << "L";
      for (long long i = 0; i < minVer; i++) cout << "U";
      for (long long i = 0; i < minHor; i++) cout << "R";
      for (long long i = 0; i < minVer; i++) cout << "D";
      cout << endl;
    } else if ((up == 0 || down == 0) && left != 0 && right != 0) {
      cout << 2 << endl;
      cout << "LR" << endl;
    } else if ((left == 0 || right == 0) && up != 0 && down != 0) {
      cout << 2 << endl;
      cout << "UD" << endl;
    } else {
      cout << 0 << endl;
      cout << endl;
    }
  }
  return 0;
}
