#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string st;
    cin >> st;
    int l = 0, r = 0, u = 0, d = 0;
    for (int j = 0; j < st.length(); j++) {
      if (st[j] == 'L') l++;
      if (st[j] == 'R') r++;
      if (st[j] == 'U') u++;
      if (st[j] == 'D') d++;
    }
    int h1 = min(l, r);
    l = h1;
    r = h1;
    int h2 = min(u, d);
    u = h2;
    d = h2;
    if (h1 == 0 && h2 != 0) {
      u = 1;
      d = 1;
      h2 = 1;
    }
    if (h2 == 0 && h1 != 0) {
      l = 1;
      r = 1;
      h1 = 1;
    }
    cout << 2 * h1 + 2 * h2 << endl;
    while (true) {
      if (l + r + u + d == 0) break;
      if (l > 0) {
        cout << "L";
        l--;
        continue;
      }
      if (u > 0) {
        cout << "U";
        u--;
        continue;
      }
      if (r > 0) {
        cout << "R";
        r--;
        continue;
      }
      if (d > 0) {
        cout << "D";
        d--;
        continue;
      }
    }
    cout << endl;
  }
  return 0;
}
