#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tc;
  cin >> tc;
  while (tc--) {
    string s;
    cin >> s;
    unordered_map<char, long long> mp;
    for (auto ch : s) mp[ch]++;
    bool hasL = mp['L'];
    bool hasR = mp['R'];
    bool hasU = mp['U'];
    bool hasD = mp['D'];
    char minC;
    long long m = INT_MAX;
    for (auto p : mp) {
      if (p.second < m) {
        m = p.second;
        minC = p.first;
      }
    }
    string res = "";
    if (hasL && hasR && hasU && hasD) {
      long long minH = min(mp['L'], mp['R']);
      long long minV = min(mp['U'], mp['D']);
      for (long long i = 0; i < minH; i++) res += 'R';
      for (long long i = 0; i < minV; i++) res += 'U';
      for (long long i = 0; i < minH; i++) res += 'L';
      for (long long i = 0; i < minV; i++) res += 'D';
    } else {
      if (hasL && hasR) res += "LR";
      if (hasU && hasD) res += "UD";
    }
    if (res.size())
      cout << res.size() << '\n' << res << '\n';
    else
      cout << 0 << '\n';
  }
  return 0;
}
