#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    string a;
    cin >> a;
    long long l = 0, r = 0, u = 0, d = 0;
    for (j = 0; j < a.size(); j++) {
      if (a[j] == 'L')
        l++;
      else if (a[j] == 'U')
        u++;
      else if (a[j] == 'R')
        r++;
      else if (a[j] == 'D')
        d++;
    }
    long long x = min(l, r);
    long long y = min(u, d);
    if (x == 0 && y == 0) {
      cout << 0 << endl;
      continue;
    } else if (x == 0 || y == 0) {
      if (x == 0) {
        cout << 2 << endl;
        cout << "UD" << endl;
        continue;
      } else if (y == 0) {
        cout << 2 << endl;
        cout << "LR" << endl;
        continue;
      }
    }
    cout << 2 * (x + y) << endl;
    for (j = 0; j < x; j++) cout << "L";
    for (j = 0; j < y; j++) cout << "U";
    for (j = 0; j < x; j++) cout << "R";
    for (j = 0; j < y; j++) cout << "D";
    cout << endl;
  }
}
