#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second < b.second)
    return true;
  else if (a.second == b.second)
    return a.first < b.first;
  else
    return false;
}
bool sortbyboth(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first < b.first)
    return true;
  else if (a.first == b.first)
    return a.second < b.second;
  else
    return false;
}
unsigned long long powr(unsigned long long x1, unsigned long long n1) {
  if (x1 == 0) {
    return 0;
  }
  unsigned long long result = 1;
  while (n1 > 0) {
    if (n1 & 1) {
      result = (result * x1);
    }
    n1 = n1 >> 1;
    x1 = (x1 * x1);
  }
  return result;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    int l = 0, r = 0, u = 0, d = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'L')
        l++;
      else if (s[i] == 'R')
        r++;
      else if (s[i] == 'U')
        u++;
      else
        d++;
    }
    int r1 = min(d, u);
    int r2 = min(r, l);
    if (r1 == 0) {
      if (r2 == 0) {
        cout << 0 << endl;
      } else {
        cout << 2 << endl;
        cout << "LR" << endl;
      }
    } else {
      if (r2 == 0) {
        cout << 2 << endl;
        cout << "UD" << endl;
      } else {
        cout << 2 * r1 + 2 * r2 << endl;
        for (int i = 0; i < r2; i++) cout << "L";
        for (int i = 0; i < r1; i++) cout << "D";
        for (int i = 0; i < r2; i++) cout << "R";
        for (int i = 0; i < r1; i++) cout << "U";
        cout << endl;
      }
    }
  }
  return 0;
}
