#include <bits/stdc++.h>
using namespace std;
long long int MOD = (1e9) + 7;
inline void fastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
int main() {
  fastIO();
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    string s;
    cin >> s;
    int u = 0, d = 0, l = 0, r = 0;
    for (int i = 0; i < s.length(); i++) {
      s[i] == 'U' ? u++ : u = u;
      s[i] == 'D' ? d++ : d = d;
      s[i] == 'L' ? l++ : l = l;
      s[i] == 'R' ? r++ : r = r;
    }
    int width = min(l, r);
    int height = min(u, d);
    if (width == 0 && height == 0) {
      cout << 0 << endl;
      continue;
    } else if (width == 0 || height == 0) {
      if (width == 0) {
        cout << 2 << endl;
        cout << "UD" << endl;
      } else {
        cout << 2 << endl;
        cout << "LR" << endl;
      }
    } else {
      cout << (width + height) * 2 << endl;
      r = width, l = width, u = height, d = height;
      while (r > 0) {
        r--;
        cout << "R";
      }
      while (u > 0) {
        u--;
        cout << "U";
      }
      while (l > 0) {
        l--;
        cout << "L";
      }
      while (d > 0) {
        d--;
        cout << "D";
      }
      cout << endl;
    }
  }
}
