#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (int w = 0; w < q; w++) {
    string s;
    cin >> s;
    int n = s.length();
    int up = 0, dow = 0, r = 0, l = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'U') {
        up++;
      }
      if (s[i] == 'D') {
        dow++;
      }
      if (s[i] == 'R') {
        r++;
      }
      if (s[i] == 'L') {
        l++;
      }
    }
    string ans = "";
    if (min(l, r) == 0 && min(up, dow) != 0) {
      cout << 2 << endl;
      cout << "UD" << endl;
    } else if (min(l, r) != 0 && min(up, dow) == 0) {
      cout << 2 << endl;
      cout << "LR" << endl;
    } else if (min(l, r) == 0 && min(up, dow) == 0) {
      cout << 0 << endl;
      cout << endl;
    } else {
      for (int i = 0; i < min(up, dow); i++) {
        ans += 'U';
      }
      for (int i = 0; i < min(l, r); i++) {
        ans += 'L';
      }
      for (int i = 0; i < min(up, dow); i++) {
        ans += 'D';
      }
      for (int i = 0; i < min(l, r); i++) {
        ans += 'R';
      }
      cout << ans.length() << endl;
      cout << ans << endl;
    }
  }
  return 0;
}
