#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 7;
const int INF = 1e9;
const long long INFF = 1e18;
string str;
int main() {
  int q;
  cin >> q;
  while (q--) {
    cin >> str;
    int sz = str.size(), L = 0, R = 0, D = 0, U = 0;
    for (int i = 0; i < sz; i++) {
      if (str[i] == 'L')
        L++;
      else if (str[i] == 'R')
        R++;
      else if (str[i] == 'D')
        D++;
      else if (str[i] == 'U')
        U++;
    }
    int minn1 = min(L, R);
    int minn2 = min(U, D);
    if (minn1 == 0 && minn2 >= 1) {
      cout << 2 << endl;
      cout << "UD" << endl;
    } else if (minn2 == 0 && minn1 >= 1) {
      cout << 2 << endl;
      cout << "RL" << endl;
    } else {
      cout << 2 * (minn1 + minn2) << endl;
      for (int i = 1; i <= minn1; i++) cout << "R";
      for (int i = 1; i <= minn2; i++) cout << "D";
      for (int i = 1; i <= minn1; i++) cout << "L";
      for (int i = 1; i <= minn2; i++) cout << "U";
      cout << endl;
    }
  }
  return 0;
}
