#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  long long int l = 0, r = 0, u = 0, d = 0;
  for (long long 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++;
  }
  long long int h = min(l, r);
  long long int v = min(u, d);
  if (!h && v)
    cout << "2\nUD\n";
  else if (h && !v)
    cout << "2\nLR\n";
  else if (h && v) {
    cout << 2 * v + 2 * h << "\n";
    for (long long int i = 0; i < h; i++) cout << "L";
    for (long long int i = 0; i < v; i++) cout << "U";
    for (long long int i = 0; i < h; i++) cout << "R";
    for (long long int i = 0; i < v; i++) cout << "D";
    cout << "\n";
  } else
    cout << "0\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
