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