#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long int nr = 0, nl = 0, nu = 0, nd = 0, nx, ny;
    vector<char> v;
    for (long long int i = 0; i < s.length(); i++) {
      if (s[i] == 'R')
        nr++;
      else if (s[i] == 'L')
        nl++;
      else if (s[i] == 'U')
        nu++;
      else if (s[i] == 'D')
        nd++;
    }
    if (nr < nl)
      nx = nr;
    else
      nx = nl;
    if (nu < nd)
      ny = nu;
    else
      ny = nd;
    for (long long int i = 0; i < 2 * (nx + ny); i++) {
      if (i < nx) {
        v.push_back('R');
      } else if (i < (ny + nx) && i >= (nx)) {
        v.push_back('U');
      } else if (i < (ny + 2 * nx) && i >= (nx + ny)) {
        v.push_back('L');
      } else if (i < (2 * ny + 2 * nx) && i >= (2 * nx + ny)) {
        v.push_back('D');
      }
    }
    if (v.size() == 0)
      cout << 0 << endl;
    else if (ny == 0) {
      cout << "2" << endl;
      cout << "LR" << endl;
    } else if (nx == 0) {
      cout << "2" << endl;
      cout << "UD" << endl;
    } else {
      cout << v.size() << endl;
      for (long long int i = 0; i < v.size(); i++) cout << v[i];
      cout << endl;
    }
  }
}
