#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int n = s.length();
  int r = 0, l = 0, u = 0, d = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R')
      r++;
    else if (s[i] == 'L')
      l++;
    else if (s[i] == 'U')
      u++;
    else if (s[i] == 'D')
      d++;
  }
  if (l == 0 || r == 0) {
    if (u == 0 || d == 0)
      cout << "0" << endl << endl;
    else
      cout << "2" << endl << "UD" << endl;
  } else if (u == 0 || d == 0) {
    if (l == 0 || r == 0)
      cout << "0" << endl << endl;
    else
      cout << "2" << endl << "LR" << endl;
  } else {
    int k = min(l, r);
    int j = min(u, d);
    cout << (k + j) * 2 << endl;
    for (int i = 0; i < k; i++) cout << "L";
    for (int i = 0; i < j; i++) cout << "U";
    for (int i = 0; i < k; i++) cout << "R";
    for (int i = 0; i < j; i++) cout << "D";
    cout << endl;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
