#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    map<char, int> mp;
    for (auto it : s) mp[it]++;
    mp['R'] = min(mp['R'], mp['L']);
    mp['L'] = min(mp['R'], mp['L']);
    mp['U'] = min(mp['U'], mp['D']);
    mp['D'] = min(mp['U'], mp['D']);
    if (mp['L'] == 0 && mp['U'] > 0) mp['U'] = 1;
    if (mp['U'] == 0 && mp['L'] > 0) mp['L'] = 1;
    mp['R'] = min(mp['R'], mp['L']);
    mp['L'] = min(mp['R'], mp['L']);
    mp['U'] = min(mp['U'], mp['D']);
    mp['D'] = min(mp['U'], mp['D']);
    string ans;
    for (int i = 0; i < mp['R']; ++i) ans += "R";
    for (int i = 0; i < mp['D']; ++i) ans += "D";
    for (int i = 0; i < mp['L']; ++i) ans += "L";
    for (int i = 0; i < mp['U']; ++i) ans += "U";
    cout << ans.size() << "\n" << ans << "\n";
  }
  return 0;
}
