#include <bits/stdc++.h>
bool check(int a) { return (a & (a - 1)) == 0 ? true : false; }
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 9;
long long a[maxn], num[31];
void solve() {
  int L = 0, R = 0, U = 0, D = 0;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'L') L++;
    if (s[i] == 'R') R++;
    if (s[i] == 'U') U++;
    if (s[i] == 'D') D++;
  }
  int l = min(L, R), u = min(U, D);
  if (l == 0 && u != 0) u = 1;
  if (u == 0 && l != 0) l = 1;
  cout << (l + u) * 2 << endl;
  for (int i = 1; i <= l; i++) cout << "L";
  for (int i = 1; i <= u; i++) cout << "U";
  for (int i = 1; i <= l; i++) cout << "R";
  for (int i = 1; i <= u; i++) cout << "D";
  cout << endl;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
