#include <bits/stdc++.h>
using namespace std;
string mv = "LRUD";
int ary[4];
vector<char> V;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    memset(ary, 0, sizeof(ary));
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); ++i) {
      for (int j = 0; j < 4; ++j) {
        if (s[i] == mv[j]) ++ary[j];
      }
    }
    ary[0] = ary[1] = min(ary[0], ary[1]);
    ary[2] = ary[3] = min(ary[2], ary[3]);
    if (ary[0] == 0) ary[2] = ary[3] = (ary[2] == 0) ? 0 : 1;
    if (ary[2] == 0) ary[0] = ary[1] = (ary[1] == 0) ? 0 : 1;
    cout << ary[0] * 2 + ary[2] * 2 << '\n';
    for (ary[0]; ary[0] > 0; --ary[0]) cout << "L";
    for (ary[2]; ary[2] > 0; --ary[2]) cout << "U";
    for (ary[1]; ary[1] > 0; --ary[1]) cout << "R";
    for (ary[3]; ary[3] > 0; --ary[3]) cout << "D";
    cout << '\n';
  }
  return 0;
}
