#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
const int M = 1000100;
const long long mod = 998244353;
int main() {
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    int l = 0, r = 0, u = 0, d = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == 'L') l++;
      if (s[i] == 'R') r++;
      if (s[i] == 'U') u++;
      if (s[i] == 'D') d++;
    }
    int ss = 0;
    int minl = min(l, r);
    int okl = 0, oku = 0;
    if (minl != 0) {
      okl = 1;
    }
    ss += minl;
    int minu = min(u, d);
    if (minu != 0) {
      oku = 1;
    }
    ss += minu;
    if (okl && oku) {
      cout << ss * 2 << endl;
      for (int i = 1; i <= minl; i++) {
        cout << "L";
      }
      for (int i = 1; i <= minu; i++) {
        cout << "U";
      }
      for (int i = 1; i <= minl; i++) {
        cout << "R";
      }
      for (int i = 1; i <= minu; i++) {
        cout << "D";
      }
      cout << endl;
    } else if (okl && !oku) {
      cout << 2 << endl;
      cout << "LR" << endl;
    } else if (!okl && oku) {
      cout << 2 << endl;
      cout << "UD" << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}
