#include <bits/stdc++.h>
using namespace std;
void faster() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  if (0) {
    freopen(
        "input"
        ".in",
        "r", stdin);
    freopen(
        "input"
        ".out",
        "w", stdout);
  }
}
int l, r, d, u, a, b, ans;
string s;
int main() {
  faster();
  int q;
  cin >> q;
  while (q--) {
    cin >> s;
    l = r = u = d = 0;
    for (int i = 0; i < int(s.size()); i++) {
      if (s[i] == 'L') l++;
      if (s[i] == 'R') r++;
      if (s[i] == 'D') d++;
      if (s[i] == 'U') u++;
    }
    a = 2 * min(l, r);
    b = 2 * min(u, d);
    ans = a + b;
    if (!a && b) {
      cout << 2 << endl;
      cout << "UD" << endl;
      continue;
    }
    if (!b && a) {
      cout << 2 << endl;
      cout << "LR" << endl;
      continue;
    }
    cout << ans << endl;
    a >>= 1;
    b >>= 1;
    for (int i = 0; i < int(a); i++) cout << 'L';
    for (int i = 0; i < int(b); i++) cout << 'U';
    for (int i = 0; i < int(a); i++) cout << 'R';
    for (int i = 0; i < int(b); i++) cout << 'D';
    cout << endl;
  }
  return 0;
}
