#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 34;
inline void dbg() { cerr << endl; }
template <typename T, typename... V>
inline void dbg(T t, V... v) {
  cerr << ' ' << t;
  dbg(v...);
}
void solve() {
  string str, ans = "";
  cin >> str;
  map<char, int> make_pair;
  for (int i = 0; i < str.size(); i++) {
    make_pair[str[i]]++;
  }
  int l = min(make_pair['L'], make_pair['R']);
  int u = min(make_pair['U'], make_pair['D']);
  if (l != 0 && u == 0) {
    cout << 2 << endl;
    cout << "LR" << endl;
    return;
  }
  if (l == 0 && u != 0) {
    cout << 2 << endl;
    cout << "UD" << endl;
    return;
  }
  for (int i = 0; i < l; i++) {
    ans.push_back('L');
  }
  for (int i = 0; i < u; i++) {
    ans.push_back('U');
  }
  for (int i = 0; i < l; i++) {
    ans.push_back('R');
  }
  for (int i = 0; i < u; i++) {
    ans.push_back('D');
  }
  cout << ans.size() << endl;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
