#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 100;
int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dy[] = {0, 0, -1, 1, 1, -1, -1, 1};
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int up = 0, down = 0, le = 0, ri = 0;
    for (int i = 0; i < s.length(); ++i) {
      if (s[i] == 'U') {
        up++;
      } else if (s[i] == 'D') {
        down++;
      } else if (s[i] == 'L') {
        le++;
      } else {
        ri++;
      }
    }
    int cnt = 0;
    string now = "";
    int mud = min(up, down);
    int mlr = min(le, ri);
    int ma = max(mud, mlr);
    if (mlr == 0) {
      if (mud > 0) {
        cout << 2 << '\n';
        cout << "UD" << '\n';
      } else {
        cout << 0 << '\n';
        cout << "" << '\n';
      }
    } else if (mud == 0) {
      if (mlr > 0) {
        cout << 2 << '\n';
        cout << "LR" << '\n';
      } else {
        cout << 0 << '\n';
        cout << "" << '\n';
      }
    } else {
      for (int i = 0; i < mlr; ++i) {
        now += "R";
        cnt++;
      }
      for (int i = 0; i < mud; ++i) {
        now += "U";
        cnt++;
      }
      for (int i = 0; i < mlr; ++i) {
        now += "L";
        cnt++;
      }
      for (int i = 0; i < mud; ++i) {
        now += "D";
        cnt++;
      }
      cout << cnt << '\n';
      cout << now << '\n';
    }
  }
}
