#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    int up = 0, dow = 0, lf = 0, rg = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'U')
        up++;
      else if (s[i] == 'D')
        dow++;
      else if (s[i] == 'L')
        lf++;
      else
        rg++;
    }
    if (up >= 1 && dow >= 1 && lf >= 1 && rg >= 1) {
      cout << 2 * min(up, dow) + 2 * min(rg, lf) << endl;
      for (int i = 0; i < min(up, dow); i++) cout << "U";
      for (int i = 0; i < min(lf, rg); i++) cout << "L";
      for (int i = 0; i < min(up, dow); i++) cout << "D";
      for (int i = 0; i < min(lf, rg); i++) cout << "R";
      cout << endl;
    } else {
      if (up >= 1 && dow >= 1) {
        cout << 2 << endl;
        cout << "UD" << endl;
      } else if (rg >= 1 && lf >= 1) {
        cout << 2 << endl;
        cout << "LR" << endl;
      } else
        cout << 0 << endl;
    }
  }
}
