#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    long long int l = 0, u = 0, r = 0, d = 0;
    cin >> s;
    long long int x, y;
    for (long long int i = 0; i < s.length(); i++) {
      if (s[i] == 'L') l++;
      if (s[i] == 'R') r++;
      if (s[i] == 'D') d++;
      if (s[i] == 'U') u++;
    }
    l = min(l, r);
    u = min(u, d);
    if (u == 0 || l == 0) {
      if (u == 0 && l >= 1)
        cout << "2\n"
             << "RL";
      else if (u >= 1)
        cout << "2\n"
             << "UD";
      else
        cout << "0\n";
    } else {
      cout << (u + l) * 2 << "\n";
      for (long long int i = 0; i < u; i++) cout << "U";
      for (long long int i = 0; i < l; i++) cout << "R";
      for (long long int i = 0; i < u; i++) cout << "D";
      for (long long int i = 0; i < l; i++) cout << "L";
    }
    cout << "\n";
  }
  return 0;
}
