import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}
void main()
{
  int q; get(q);
  while(q--)
    {
      int[4] count = 0;
      string str; get(str);
      foreach(c; str)
	{
	  switch(c)
	    {
	    case 'L':
	      count[0]++;
	      break;
	    case 'R':
	      count[1]++;
	      break;
	    case 'U':
	      count[2]++;
	      break;
	    case 'D':
	      count[3]++;
	      break;
	    default:
	      assert(0);
	    }
	}
      int l = min(count[0], count[1]);
      int r = min(count[2], count[3]);
      if(l == 0 && r > 1)
	{
	  r = 1;
	}
      if(l > 1 && r == 0)
	{
	  l = 1;
	}
      wr(2 * (l + r));
      foreach(i; 0 .. r)
	write('U');
      foreach(i; 0 .. l)
	write('R');
      foreach(i; 0 .. r)
	write('D');
      foreach(i; 0 .. l)
	write('L');
      if(l + r)
	writeln;
    }
}
