#include <bits/stdc++.h>
using namespace std;
void solve() { return; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    long long n = s.length();
    long long u = 0, d = 0, r = 0, l = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'U')
        u++;
      else if (s[i] == 'D')
        d++;
      else if (s[i] == 'L')
        l++;
      else
        r++;
    }
    vector<char> v;
    long long p = min(u, d);
    u = d = p;
    long long q = min(l, r);
    l = r = q;
    if ((u != 0) && (l != 0) && (r != 0) && (d != 0)) {
      while (u--) v.push_back('U');
      while (r--) v.push_back('R');
      while (d--) v.push_back('D');
      while (l--) v.push_back('L');
    } else {
      if ((u != 0) && (d != 0)) {
        v.push_back('U');
        v.push_back('D');
      } else if ((r != 0) && (l != 0)) {
        v.push_back('L');
        v.push_back('R');
      }
    }
    cout << v.size() << '\n';
    for (int i = 0; i < v.size(); i++) cout << v[i];
    cout << '\n';
  }
}
