#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int u = 0, d = 0, l = 0, r = 0;
    for (char c : s) {
      if (c == 'U') u++;
      if (c == 'R') r++;
      if (c == 'D') d++;
      if (c == 'L') l++;
    }
    u = d = min(u, d);
    l = r = min(l, r);
    if ((u == 0 && l > 1)) {
      cout << "2\nLR" << '\n';
    } else if ((l == 0 && u > 1)) {
      cout << "2\nUD" << '\n';
    } else {
      cout << 2 * l + 2 * u << '\n';
      while (l--) cout << "L";
      while (u--) cout << "U";
      while (r--) cout << "R";
      while (d--) cout << "D";
      cout << '\n';
    }
  }
  return 0;
}
