#include <bits/stdc++.h>
using namespace std;
void speed() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const long long N = 1e5 + 5;
const long long NN = 105;
const long long MAX = 2e5 + 123;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
void hajime() {
  string s;
  long long l = 0, r = 0, d = 0, u = 0;
  cin >> s;
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == 'L')
      l++;
    else if (s[i] == 'R')
      r++;
    else if (s[i] == 'D')
      d++;
    else if (s[i] == 'U')
      u++;
  }
  l = min(l, r);
  u = min(u, d);
  if (u == 0 && l > 0) l = 1;
  if (l == 0 && u > 0) u = 1;
  cout << l * 2 + u * 2 << '\n';
  r = l;
  d = u;
  while (l--) cout << 'L';
  while (u--) cout << 'U';
  while (r--) cout << 'R';
  while (d--) cout << 'D';
  cout << '\n';
}
int main() {
  speed();
  long long miyagi = 1;
  cin >> miyagi;
  while (miyagi--) hajime();
}
