#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int nl = 0, nr = 0, nu = 0, nd = 0;
    int l = s.length();
    for (int i = 0; i < l; i++) {
      if (s[i] == 'L')
        nl++;
      else if (s[i] == 'R')
        nr++;
      else if (s[i] == 'U')
        nu++;
      else
        nd++;
    }
    int nh = min(nl, nr), nv = min(nu, nd);
    if (nh == 0) {
      if (nv == 0)
        cout << 0 << endl << endl;
      else
        cout << 2 << "\nUD\n";
    } else if (nv == 0)
      cout << 2 << "\nLR\n";
    else {
      cout << 2 * (nh + nv) << endl;
      for (int i = 0; i < nh; i++) cout << 'L';
      for (int i = 0; i < nv; i++) cout << 'U';
      for (int i = 0; i < nh; i++) cout << 'R';
      for (int i = 0; i < nv; i++) cout << 'D';
      cout << endl;
    }
  }
  return 0;
}
