#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long factorial(long long n) {
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = ((res % mod) * (x % mod)) % mod;
    y = y >> 1;
    x = ((x % mod) * (x % mod)) % mod;
  }
  return res;
}
long long ncr(long long n, long long r) {
  long long res = 1;
  if (r > n) return 0;
  if (r > n - r) r = n - r;
  for (long long i = 0; i < r; i++) {
    res = ((res % mod) * ((n - i) % mod)) % mod;
    res = ((res % mod) * (power(i + 1, mod - 2)) % mod) % mod;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }
long long max(long long a, long long b) {
  long long sol = a > b ? a : b;
  return sol;
}
long long min(long long a, long long b) {
  long long sol = a < b ? a : b;
  return sol;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    map<char, long long> make_pair;
    for (char c : s) {
      make_pair[c]++;
    }
    {
      {
        make_pair['L'] = min(make_pair['L'], make_pair['R']);
        make_pair['R'] = min(make_pair['L'], make_pair['R']);
        make_pair['U'] = min(make_pair['U'], make_pair['D']);
        make_pair['D'] = min(make_pair['U'], make_pair['D']);
        if (make_pair['L'] == make_pair['R'] and make_pair['U'] == 0 and
            make_pair['D'] == 0 and make_pair['L'] != 0)
          cout << 2 << "\n"
               << "LR\n";
        else if (make_pair['U'] == make_pair['D'] and make_pair['R'] == 0 and
                 make_pair['L'] == 0 and make_pair['U'] != 0)
          cout << 2 << "\n"
               << "UD\n";
        else {
          cout << make_pair['L'] + make_pair['R'] + make_pair['U'] +
                      make_pair['D']
               << "\n";
          for (long long i = 0; i < make_pair['D']; i++) {
            cout << 'D';
          }
          for (long long i = 0; i < make_pair['L']; i++) {
            cout << 'L';
          }
          for (long long i = 0; i < make_pair['U']; i++) {
            cout << 'U';
          }
          for (long long i = 0; i < make_pair['R']; i++) {
            cout << 'R';
          }
          cout << "\n";
        }
      }
    }
  }
}
