#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
const double eps = 1e-9;
const long long INF = 1e18;
signed main() {
  long long q;
  cin >> q;
  string a;
  while (q--) {
    cin >> a;
    long long n = a.size();
    long long l = 0, r = 0, u = 0, d = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i] == 'L') l++;
      if (a[i] == 'R') r++;
      if (a[i] == 'U') u++;
      if (a[i] == 'D') d++;
    }
    if (min(u, d) == min(l, r) && min(l, r) == 0) {
      cout << "0" << endl;
      cout << endl;
      continue;
    }
    if (min(u, d) == 0) {
      cout << 2 << endl;
      cout << "LR" << endl;
      continue;
    }
    if (min(l, r) == 0) {
      cout << 2 << endl;
      cout << "UD" << endl;
      continue;
    }
    cout << min(l, r) * 2 + min(u, d) * 2 << endl;
    for (long long i = 1; i <= min(l, r); i++) {
      cout << "L";
    }
    for (long long i = 1; i <= min(u, d); i++) {
      cout << "D";
    }
    for (long long i = 1; i <= min(l, r); i++) {
      cout << "R";
    }
    for (long long i = 1; i <= min(u, d); i++) {
      cout << "U";
    }
    cout << endl;
  }
  return 0;
}
