#include <bits/stdc++.h>
const long long template_array_size = 1e6;
const long long INF = 9223372036854775807;
const long double PI = acosl(-1.0);
const long long MOD = 1e9 + 7;
using namespace std;
bool visited[100005];
long long n, m, x, y;
const long long N = 1e7 + 7;
void solve() {
  string s;
  cin >> s;
  long long u = 0;
  long long d = 0;
  long long l = 0;
  long long r = 0;
  for (char c : s) {
    if (c == 'U') u++;
    if (c == 'D') d++;
    if (c == 'L') l++;
    if (c == 'R') r++;
  }
  u = min(u, d);
  d = min(u, d);
  r = min(l, r);
  l = min(l, r);
  if (u == 0 && l == 0) {
    cout << 0 << endl;
    return;
  } else if (u == 0) {
    cout << "2\nLR\n";
    return;
  } else if (l == 0) {
    cout << "2\nUD\n";
    return;
  }
  string res;
  for (int i = 0; i < u; ++i) {
    res += "U";
  }
  for (int i = 0; i < l; ++i) {
    res += "L";
  }
  for (int i = 0; i < d; ++i) {
    res += "D";
  }
  for (int i = 0; i < r; ++i) {
    res += "R";
  }
  cout << res.size() << endl << res << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(15);
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
