#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    string z = "";
    cin >> s;
    int r, l, u, d;
    r = l = d = u = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == 'U')
        u++;
      else if (s[i] == 'D')
        d++;
      else if (s[i] == 'R')
        r++;
      else
        l++;
    }
    int rl = min(r, l), ud = min(u, d);
    if (d && u && r && l) {
      cout << rl * 2 + ud * 2 << endl;
      for (int i = 0; i < rl; i++) cout << 'R';
      for (int i = 0; i < ud; i++) cout << 'U';
      for (int i = 0; i < rl; i++) cout << 'L';
      for (int i = 0; i < ud; i++) {
        cout << 'D';
      }
      cout << endl;
      continue;
    } else if (r && l) {
      cout << 2 << endl;
      cout << "R"
           << "L" << endl;
      continue;
    } else if (u && d) {
      cout << 2 << endl;
      cout << "U"
           << "D" << endl;
      continue;
    }
    cout << 0 << endl << endl;
  }
  return 0;
}
