#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long oo = 1e18 + 7;
const int N = 2e5 + 7;
int n, q;
string second;
int m[20];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> q;
  while (q--) {
    cin >> second;
    n = second.size();
    for (int i = 0; i < second.size(); i++) {
      if (second[i] == 'L') m[0]++;
      if (second[i] == 'R') m[1]++;
      if (second[i] == 'U') m[2]++;
      if (second[i] == 'D') m[3]++;
    }
    int cnt = 0;
    long long res = n;
    res = res - (max(m[0], m[1]) - min(m[0], m[1])) -
          (max(m[2], m[3]) - min(m[2], m[3]));
    for (int i = 0; i <= 3; i++)
      if (m[i] == 0) cnt++;
    if (cnt >= 3) {
      cout << 0 << "\n";
      for (int i = 0; i <= 4; i++) m[i] = 0;
      continue;
    }
    if (m[3] == 0 || m[2] == 0) {
      if (m[1] != 0 && m[0] != 0)
        cout << 2 << "\nLR\n";
      else
        cout << "0\n";
      for (int i = 0; i <= 4; i++) m[i] = 0;
      continue;
    }
    if (m[0] == 0 || m[1] == 0) {
      if (m[2] != 0 && m[3] != 0)
        cout << 2 << "\nUD\n";
      else
        cout << "0\n";
      for (int i = 0; i <= 4; i++) m[i] = 0;
      continue;
    }
    cout << res << "\n";
    for (int i = 1; i <= min(m[0], m[1]); i++) cout << 'L';
    for (int i = 1; i <= min(m[3], m[2]); i++) cout << 'U';
    for (int i = 1; i <= min(m[0], m[1]); i++) cout << 'R';
    for (int i = 1; i <= min(m[3], m[2]); i++) cout << 'D';
    cout << "\n";
    for (int i = 0; i <= 4; i++) m[i] = 0;
  }
  return 0;
}
