#include <bits/stdc++.h>
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int maxn = 100100;
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    int a = 0, b = 0, c = 0, d = 0;
    for (int i = 0; i <= (int)s.length() - 1; ++i) {
      if (s[i] == 'L')
        a++;
      else if (s[i] == 'R')
        b++;
      else if (s[i] == 'U')
        c++;
      else if (s[i] == 'D')
        d++;
    }
    int temp1 = min(a, b);
    int temp2 = min(c, d);
    if (temp1 == 0 && temp2 == 0)
      cout << 0 << endl;
    else if (temp1 != 0 && temp2 != 0) {
      cout << temp1 * 2 + temp2 * 2 << endl;
      for (int i = 1; i <= temp1; ++i) cout << "L";
      for (int i = 1; i <= temp2; ++i) cout << "U";
      for (int i = 1; i <= temp1; ++i) cout << "R";
      for (int i = 1; i <= temp2; ++i) cout << "D";
      cout << endl;
    } else {
      if (temp1 != 0) {
        cout << 2 << endl;
        cout << "LR" << endl;
      } else {
        cout << 2 << endl;
        cout << "UD" << endl;
      }
    }
  }
}
