#include <bits/stdc++.h>
using namespace std;
string s;
int h[200], cnt[4];
int main() {
  h['R'] = 1, h['U'] = 2, h['D'] = 3;
  int T;
  cin >> T;
  while (T--) {
    memset(cnt, 0, sizeof(cnt));
    cin >> s;
    for (int i = 0; i < s.size(); ++i) ++cnt[h[s[i]]];
    int Min = *min_element(cnt, cnt + 4);
    if (!Min) {
      if (min(cnt[0], cnt[1]))
        cout << "2\nLR" << endl;
      else if (min(cnt[2], cnt[3]))
        cout << "2\nUD" << endl;
      else
        cout << 0 << endl << endl;
      continue;
    }
    int c1 = min(cnt[0], cnt[1]), c2 = min(cnt[2], cnt[3]);
    string ans;
    for (int i = 0; i < c1; ++i) ans += "L";
    for (int i = 0; i < c2; ++i) ans += "D";
    for (int i = 0; i < c1; ++i) ans += "R";
    for (int i = 0; i < c2; ++i) ans += "U";
    cout << ans.size() << endl << ans << endl;
  }
  return 0;
}
