#include <bits/stdc++.h>
using namespace std;
void unique(string& A) {
  string B;
  for (int i = 0; i < A.size(); i++) {
    if (B.size() == 0 || A[i] != B.back()) B.push_back(A[i]);
  }
  A = B;
}
bool find(string A, string B) {}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    string s;
    cin >> s;
    vector<int> num(4, 0);
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'L')
        num[0]++;
      else if (s[i] == 'U')
        num[1]++;
      else if (s[i] == 'R')
        num[2]++;
      else if (s[i] == 'D')
        num[3]++;
    }
    int a = min(num[0], num[2]), b = min(num[1], num[3]);
    if (a == 0) {
      b = min(b, 1);
    } else if (b == 0) {
      a = min(a, 1);
    }
    cout << 2 * (a + b) << endl;
    for (int i = 0; i < a; i++) {
      cout << "L";
    }
    for (int i = 0; i < b; i++) {
      cout << "U";
    }
    for (int i = 0; i < a; i++) {
      cout << "R";
    }
    for (int i = 0; i < b; i++) {
      cout << "D";
    }
    if ((a + b) != 0) cout << endl;
  }
  return 0;
}
