#include <bits/stdc++.h>
using namespace std;
int main() {
  long long q;
  cin >> q;
  while (q--) {
    long long ans, i, u = 0, d = 0, l = 0, r = 0, minu, minl;
    string s;
    cin >> s;
    for (i = 0; i < s.size(); i++) {
      if (s[i] == 'U')
        u++;
      else if (s[i] == 'D')
        d++;
      else if (s[i] == 'L')
        l++;
      else
        r++;
    }
    minu = min(u, d);
    minl = min(l, r);
    if (minu == 0 && minl > 0)
      minl = 1;
    else if (minl == 0 && minu > 0)
      minu = 1;
    ans = 2 * (minu + minl);
    cout << ans << endl;
    for (i = 0; i < minu - 2; i++) cout << 'U';
    for (i = 0; i < minl; i++) cout << 'L';
    for (i = 0; i < minu; i++) cout << 'D';
    minu = min(minu, 2LL);
    for (i = 0; i < minl; i++) cout << 'R';
    for (i = 0; i < minu; i++) cout << 'U';
    cout << endl;
  }
}
