#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    int l, r, u, d;
    l = u = r = d = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'L') l++;
      if (s[i] == 'R') r++;
      if (s[i] == 'U') u++;
      if (s[i] == 'D') d++;
    }
    int vertimin = min(u, d);
    u = vertimin;
    d = vertimin;
    int horimin = min(l, r);
    l = horimin;
    r = horimin;
    if (l == 0 && d == 0) {
      cout << "0" << endl;
      continue;
    }
    if (l == 0 && d != 0) {
      cout << "2" << endl;
      cout << "UD" << endl;
      continue;
    }
    if (l != 0 && d == 0) {
      cout << "2" << endl;
      cout << "LR" << endl;
      continue;
    }
    int newn = u + l + d + r;
    cout << newn << endl;
    for (int i = 0; i < l; i++) cout << "L";
    for (int i = 0; i < u; i++) cout << "U";
    for (int i = 0; i < r; i++) cout << "R";
    for (int i = 0; i < d; i++) cout << "D";
    cout << endl;
  }
}
