#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q = 0, l = 0, r = 0, u = 0, d = 0, x = 0, y = 0;
  string s;
  cin >> q;
  while (q--) {
    cin >> s;
    l = 0;
    r = 0;
    u = 0;
    d = 0;
    for (int i = 0; i < s.length(); ++i) {
      if (s[i] == 'L')
        ++l;
      else if (s[i] == 'R')
        ++r;
      else if (s[i] == 'U')
        ++u;
      else
        ++d;
    }
    x = min(l, r);
    y = min(u, d);
    if (l == 0 || r == 0) x = 0;
    if (u == 0 || d == 0) y = 0;
    if (x == 0) {
      if (y == 0) {
        cout << "0" << endl;
        continue;
      } else {
        cout << "2" << endl;
        cout << "UD" << endl;
        continue;
      }
    } else if (y == 0) {
      cout << "2" << endl;
      cout << "LR" << endl;
      continue;
    } else {
      cout << 2 * (x + y) << endl;
      for (int i = 1; i <= y; ++i) cout << "U";
      for (int i = 1; i <= x; ++i) cout << "R";
      for (int i = 1; i <= y; ++i) cout << "D";
      for (int i = 1; i <= x; ++i) cout << "L";
      cout << endl;
      continue;
    }
  }
}
