#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int d, l, u, r;
    d = l = 0;
    u = r = 0;
    for (auto x : s) {
      if (x == 'D') {
        d++;
      }
      if (x == 'L') {
        l++;
      }
      if (x == 'U') {
        u++;
      }
      if (x == 'R') {
        r++;
      }
    }
    int ans1 = min(l, r);
    int ans2 = min(u, d);
    string res = "";
    if (ans1 == 0 && ans2 == 0) {
      cout << 0 << '\n';
      cout << '\n';
    } else {
      if (ans1 != 0 && ans2 != 0) {
        for (int i = 0; i < ans1; i++) {
          res += "L";
        }
        for (int i = 0; i < ans2; i++) {
          res += "U";
        }
        for (int i = 0; i < ans1; i++) {
          res += "R";
        }
        for (int i = 0; i < ans2; i++) {
          res += "D";
        }
        cout << res.length() << '\n';
        cout << res << '\n';
      } else if (ans1 != 0 && ans2 == 0) {
        cout << 2 << '\n';
        cout << "LR" << '\n';
      } else {
        cout << 2 << '\n';
        cout << "UD" << '\n';
      }
    }
  }
  return 0;
}
