#include <bits/stdc++.h>
using namespace std;
string ans = "LRUD";
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    int a[5] = {0};
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == 'L') {
        ++a[0];
      } else if (s[i] == 'R') {
        ++a[1];
      } else if (s[i] == 'U') {
        ++a[2];
      } else {
        ++a[3];
      }
    }
    int ma = s.size();
    for (int i = 0; i < 4; ++i) {
      ma = min(ma, a[i]);
    }
    if (!ma) {
      if (a[0] && a[1]) {
        cout << 2 << endl;
        cout << "LR" << endl;
      } else if (a[2] && a[3]) {
        cout << 2 << endl;
        cout << "UD" << endl;
      } else {
        cout << 0 << endl;
      }
    } else {
      int num[5];
      int p[] = {0, 2, 1, 3};
      num[0] = num[1] = min(a[0], a[1]);
      num[2] = num[3] = min(a[2], a[3]);
      cout << 2 * (num[1] + num[2]) << endl;
      for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < num[p[i]]; ++j) {
          cout << ans[p[i]];
        }
      }
      cout << endl;
    }
  }
  return 0;
}
