#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long int l = 0, r = 0, u = 0, d = 0;
    for (int a = 0; a < s.size(); a++) {
      if (s[a] == 'L')
        l++;
      else if (s[a] == 'R')
        r++;
      else if (s[a] == 'U')
        u++;
      else
        d++;
    }
    l = min(l, r);
    d = min(d, u);
    r = l;
    u = d;
    if (l == 0 && d == 0) {
      cout << 0 << "\n";
      cout << "\n";
      continue;
    } else if (l == 0 || d == 0) {
      cout << 2 << "\n";
      if (l > 0) cout << 'R';
      if (d > 0) cout << 'D';
      if (l > 0) cout << 'L';
      if (d > 0) cout << 'U';
      cout << "\n";
    } else {
      cout << 2 * l + 2 * d << "\n";
      for (int a = 0; a < l; a++) cout << 'R';
      for (int a = 0; a < d; a++) cout << 'D';
      for (int a = 0; a < l; a++) cout << 'L';
      for (int a = 0; a < u; a++) cout << 'U';
      cout << "\n";
    }
  }
  return 0;
}
