#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
class Task {
 public:
  void solve(istream& in, ostream& out) {
    int tt;
    in >> tt;
    while (tt--) {
      string S;
      in >> S;
      vector<int> cnt(4, 0);
      for (auto s : S) {
        if (s == 'L')
          cnt[0]++;
        else if (s == 'R')
          cnt[1]++;
        else if (s == 'U')
          cnt[2]++;
        else
          cnt[3]++;
      }
      string ans;
      for (int i = (0); i < (min(cnt[0], cnt[1])); ++i) ans += 'L';
      for (int i = (0); i < (min(cnt[2], cnt[3])); ++i) ans += 'U';
      for (int i = (0); i < (min(cnt[0], cnt[1])); ++i) ans += 'R';
      for (int i = (0); i < (min(cnt[2], cnt[3])); ++i) ans += 'D';
      map<pair<int, int>, int> mp;
      int cx = 0, cy = 0;
      for (auto a : ans) {
        if (a == 'L')
          ++cx;
        else if (a == 'R')
          --cx;
        else if (a == 'U')
          ++cy;
        else
          --cy;
        mp[{cx, cy}]++;
      }
      for (auto p : mp)
        if (p.second > 1) {
          if (min(cnt[0], cnt[1]) == 0)
            ans = "DU";
          else
            ans = "RL";
          break;
        }
      out << (int)(ans).size() << '\n';
      for (auto a : ans) out << a;
      out << '\n';
    }
  }
};
int main() {
  istream& in(cin);
  ostream& out(cout);
  ios_base::sync_with_stdio(false);
  in.tie(nullptr), out.tie(nullptr);
  Task solver;
  solver.solve(in, out);
  return 0;
}
