#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int64_t t;
  cin >> t;
  while (t--) {
    map<char, int64_t> m;
    string s;
    cin >> s;
    for (int64_t i = 0; i < s.size(); i++) m[s[i]]++;
    int64_t a = min(m['L'], m['R']), b = min(m['U'], m['D']);
    if ((a == 0 && b != 0) || (a != 0 && b == 0)) {
      if (a == 0)
        cout << "2\nUD";
      else
        cout << "2\nLR";
      goto SKIP;
    }
    cout << a * 2 + b * 2 << '\n';
    for (int64_t i = 0; i < a; i++) cout << "L";
    for (int64_t i = 0; i < b; i++) cout << "U";
    for (int64_t i = 0; i < a; i++) cout << "R";
    for (int64_t i = 0; i < b; i++) cout << "D";
  SKIP:;
    cout << '\n';
  }
}
