#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int countr = 0;
    int countd = 0;
    int countl = 0;
    int countu = 0;
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s[i] == 'U') {
        countu++;
      }
      if (s[i] == 'R') {
        countr++;
      }
      if (s[i] == 'L') {
        countl++;
      }
      if (s[i] == 'D') {
        countd++;
      }
    }
    int mini1 = min(countr, countl);
    int mini2 = min(countd, countu);
    string ss = "";
    if (mini1 == 0 && mini2 > 1) {
      mini2 = 1;
    } else if (mini2 == 0 && mini1 > 1) {
      mini1 = 1;
    }
    for (int i = 0; i < mini1; i++) {
      ss += 'R';
    }
    for (int i = 0; i < mini2; i++) {
      ss += 'D';
    }
    for (int i = 0; i < mini1; i++) {
      ss += 'L';
    }
    for (int i = 0; i < mini2; i++) {
      ss += 'U';
    }
    int nn = ss.length();
    cout << nn << endl;
    cout << ss << endl;
  }
  return 0;
}
