#include <bits/stdc++.h>
using namespace std;
void FLASH() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void SETF() { cout.ios_base::setf(ios_base::fixed); }
void UNSETF() { cout.ios_base::unsetf(ios_base::fixed); }
int ar[200001];
long long arr[200001];
void solve(int T) {
  string s;
  cin >> s;
  int lx = 0, rx = 0, ux = 0, dx = 0;
  for (auto u : s) {
    if (u == 'L')
      lx++;
    else if (u == 'R')
      rx++;
    else if (u == 'U')
      ux++;
    else
      dx++;
  }
  int mlr = min(lx, rx);
  int mud = min(ux, dx);
  if (!mlr && !mud)
    cout << "0\n";
  else if (!mlr)
    cout << "2\nUD\n";
  else if (!mud)
    cout << "2\nLR\n";
  else {
    cout << 2 * (mlr + mud) << "\n";
    for (int i = 0; i < mlr; i++) cout << "L";
    for (int i = 0; i < mud; i++) cout << "U";
    for (int i = 0; i < mlr; i++) cout << "R";
    for (int i = 0; i < mud; i++) cout << "D";
    cout << "\n";
  }
  return;
}
int main(void) {
  FLASH();
  int T;
  cin >> T;
  while (T--) solve(T);
  return 0;
}
