#include <bits/stdc++.h>
using namespace std;
int q;
int main() {
  scanf("%d", &q);
  while (q--) {
    int L, R, D, U;
    L = R = D = U = 0;
    string s;
    cin >> s;
    L = count(s.begin(), s.end(), 'L');
    R = count(s.begin(), s.end(), 'R');
    U = count(s.begin(), s.end(), 'U');
    D = count(s.begin(), s.end(), 'D');
    int minLR, minUD;
    minLR = min(L, R);
    minUD = min(U, D);
    if (minLR == 0) minUD = minUD > 0 ? 1 : 0;
    if (minUD == 0) minLR = minLR > 0 ? 1 : 0;
    string res = "";
    for (int i = 0; i < minLR; ++i) {
      res += "L";
    }
    for (int i = 0; i < minUD; ++i) {
      res += "U";
    }
    for (int i = 0; i < minLR; ++i) {
      res += "R";
    }
    for (int i = 0; i < minUD; ++i) {
      res += "D";
    }
    cout << res.size() << endl << res << endl;
  }
}
