#include <bits/stdc++.h>
using namespace std;
long long n1, n2;
std::vector<long long> a;
std::vector<long long> b;
long long counter;
int main() {
  int t;
  string str;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    cin >> str;
    int l = 0, r = 0, d = 0, u = 0;
    for (int i = 0; i < str.length(); ++i) {
      if (str[i] == 'R')
        r++;
      else if (str[i] == 'L')
        l++;
      else if (str[i] == 'U')
        u++;
      else
        d++;
    }
    l = min(l, r);
    r = l;
    u = min(u, d);
    d = u;
    if (l > 0 and u == 0) {
      l = 1;
      r = 1;
    }
    if (u > 0 and l == 0) {
      u = 1;
      d = 1;
    }
    cout << (2 * l + 2 * u) << "\n";
    for (int i = 0; i < l; ++i) {
      cout << "L";
    }
    for (int i = 0; i < d; ++i) {
      cout << "D";
    }
    for (int i = 0; i < r; ++i) {
      cout << "R";
    }
    for (int i = 0; i < u; ++i) {
      cout << "U";
    }
    cout << "\n";
  }
}
