#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  scanf("%lld", &t);
  while (t--) {
    string s;
    cin >> s;
    long long l = 0, r = 0, u = 0, d = 0;
    for (long long i = 0; i < s.size(); i++) {
      if (s[i] == 'L') {
        l++;
      }
      if (s[i] == 'R') {
        r++;
      }
      if (s[i] == 'U') {
        u++;
      }
      if (s[i] == 'D') {
        d++;
      }
    }
    long long lr = min(l, r);
    long long ud = min(u, d);
    if (ud == 0 && lr == 0) {
      cout << "0" << endl;
      continue;
    }
    if (ud == 0) {
      lr = 1;
    }
    if (lr == 0) {
      ud = 1;
    }
    cout << 2 * lr + 2 * ud << endl;
    for (long long i = 0; i < lr; i++) {
      cout << "L";
    }
    for (long long i = 0; i < ud; i++) {
      cout << "U";
    }
    for (long long i = 0; i < lr; i++) {
      cout << "R";
    }
    for (long long i = 0; i < ud; i++) {
      cout << "D";
    }
    cout << "\n";
  }
}
