#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
inline void INP();
const long long N = 3e6 + 7;
long long n, Q;
long long arr[N];
void solve() {
  string str;
  cin >> str;
  n = str.length();
  map<long long, long long> m;
  for (long long i = 0; i < (long long)n; i++) {
    if (str[i] == 'L')
      m[1]++;
    else if (str[i] == 'R')
      m[2]++;
    else if (str[i] == 'U')
      m[3]++;
    else
      m[4]++;
  }
  long long k = abs(m[1] - m[2]) + abs(m[4] - m[3]);
  if (m[4] == 0 or m[3] == 0) {
    if (m[1] * m[2] != 0) {
      cout << 2 << '\n';
      cout << "LR" << '\n';
      return;
    } else {
      cout << 0 << '\n';
      cout << '\n';
      return;
    }
  }
  if (m[1] == 0 or m[2] == 0) {
    if (m[3] * m[4] != 0) {
      cout << 2 << '\n';
      cout << "UD" << '\n';
      return;
    } else {
      cout << 0 << '\n';
      cout << '\n';
      return;
    }
  }
  cout << n - k << '\n';
  for (long long i = 0; i < (long long)min(m[1], m[2]); i++) cout << 'R';
  for (long long i = 0; i < (long long)min(m[3], m[4]); i++) cout << 'U';
  for (long long i = 0; i < (long long)min(m[1], m[2]); i++) cout << 'L';
  for (long long i = 0; i < (long long)min(m[3], m[4]); i++) cout << 'D';
  cout << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  INP();
  long long t = 1;
  cin >> t;
  while (t--) solve();
}
inline void INP() {}
