#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int cnt[5];
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(cnt, 0, sizeof cnt);
    string s;
    cin >> s;
    int len = s.length();
    for (int i = 0; i < len; i++) {
      if (s[i] == 'L') cnt[1]++;
      if (s[i] == 'R') cnt[2]++;
      if (s[i] == 'U') cnt[3]++;
      if (s[i] == 'D') cnt[4]++;
    }
    int x1 = min(cnt[1], cnt[2]), y1 = min(cnt[3], cnt[4]);
    if (x1 == 0 && y1 != 0) {
      cout << 2 << endl;
      cout << "UD" << endl;
      continue;
    } else if (y1 == 0 && x1 != 0) {
      cout << 2 << endl;
      cout << "LR" << endl;
      continue;
    }
    cout << 2 * (x1 + y1) << endl;
    for (int i = 1; i <= x1; i++) putchar('R');
    for (int i = 1; i <= y1; i++) putchar('D');
    for (int i = 1; i <= x1; i++) putchar('L');
    for (int i = 1; i <= y1; i++) putchar('U');
    puts("");
  }
  return 0;
}
