#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100010;
const long long mod = 1000000007;
const long long inf = 2000000000;
const long long inf64 = inf * inf;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t, n;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    map<char, int> cnt;
    for (auto ch : str) cnt[ch]++;
    if (min(cnt['R'], cnt['L']) == 0 and min(cnt['U'], cnt['D']) == 0)
      cout << 0 << "\n";
    else {
      cnt['R'] = cnt['L'] = min(cnt['R'], cnt['L']);
      cnt['U'] = cnt['D'] = min(cnt['U'], cnt['D']);
      if (cnt['R'] == 0) cnt['U'] = cnt['D'] = 1;
      if (cnt['U'] == 0) cnt['R'] = cnt['L'] = 1;
      string str = "RULD", res;
      for (auto ch : str)
        for (int i = 0; i < cnt[ch]; i++) res.push_back(ch);
      cout << 2 * (cnt['R'] + cnt['U']) << "\n" << res << "\n";
    }
  }
  return 0;
}
