#include <bits/stdc++.h>
using namespace std;
int q;
string s;
int dulj;
int l, r, u, d;
int main() {
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> s;
    dulj = s.length();
    l = 0;
    r = 0;
    u = 0;
    d = 0;
    for (int i = 0; i < dulj; i++) {
      if (s[i] == 'L')
        l++;
      else if (s[i] == 'R')
        r++;
      else if (s[i] == 'U')
        u++;
      else
        d++;
    }
    if (min(l, r) == 0 && min(u, d) != 0)
      cout << 2 << endl << "UD" << endl;
    else if (min(l, r) != 0 && min(u, d) == 0)
      cout << 2 << endl << "LR" << endl;
    else {
      cout << 2 * (min(l, r) + min(u, d)) << endl;
      if (min(l, r) + min(u, d) != 0) {
        for (int i = 0; i < min(l, r); i++) cout << "R";
        for (int i = 0; i < min(u, d); i++) cout << "U";
        for (int i = 0; i < min(l, r); i++) cout << "L";
        for (int i = 0; i < min(u, d); i++) cout << "D";
        cout << endl;
      }
    }
  }
  return 0;
}
