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