#include <bits/stdc++.h>
using namespace std;
int main() {
  long long q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    long long n = s.length();
    long long cl = 0, cr = 0, cd = 0, cu = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'L') {
        cl++;
      } else if (s[i] == 'U') {
        cu++;
      } else if (s[i] == 'D') {
        cd++;
      } else if (s[i] == 'R') {
        cr++;
      }
    }
    long long nh = 0, nl = 0;
    nh = min(cd, cu);
    nl = min(cr, cl);
    if (nh == 0 and nl == 0) {
      cout << 0 << endl;
    } else if (nh == 0 or nl == 0) {
      if (nh != 0) {
        cout << 2 << endl;
        cout << "DU" << endl;
      } else if (nl != 0) {
        cout << 2 << endl;
        cout << "LR" << endl;
      }
    } else {
      cout << 2 * nh + 2 * nl << endl;
      for (int i = 0; i < nl; i++) {
        cout << "L";
      }
      for (int i = 0; i < nh; i++) {
        cout << "D";
      }
      for (int i = 0; i < nl; i++) {
        cout << "R";
      }
      for (int i = 0; i < nh; i++) {
        cout << "U";
      }
      cout << endl;
    }
  }
  return 0;
}
