#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long l = 0, u = 0, d = 0, r = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == 'L')
        l++;
      else if (s[i] == 'R')
        r++;
      else if (s[i] == 'U')
        u++;
      else if (s[i] == 'D')
        d++;
    }
    int v = min(l, r);
    int x = min(u, d);
    if (v == 0 || x == 0) {
      v = min(v, 1);
      x = min(x, 1);
    }
    string ans;
    for (int i = 0; i < v; ++i) {
      ans += 'R';
    }
    for (int i = 0; i < x; ++i) {
      ans += 'U';
    }
    for (int i = 0; i < v; ++i) {
      ans += 'L';
    }
    for (int i = 0; i < x; ++i) {
      ans += 'D';
    }
    cout << ans.length() << "\n" << ans << "\n";
  }
}
