#include <bits/stdc++.h>
using namespace std;
long long t;
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> s;
    long long n = s.size();
    long long D = 0, U = 0, L = 0, R = 0;
    for (long long i = 0; i < n; i++) {
      if (s[i] == 'D')
        D++;
      else if (s[i] == 'U')
        U++;
      else if (s[i] == 'L')
        L++;
      else if (s[i] == 'R')
        R++;
    }
    long long D2 = 0, U2 = 0, L2 = 0, R2 = 0, ok = 0;
    if (D > U) D = U;
    if (U > D) U = D;
    if (L > R) L = R;
    if (R > L) R = L;
    if (!D && !R) {
      cout << 0 << endl;
      continue;
    }
    if (!D || !R) {
      cout << 2 << endl;
      if (!D) cout << "RL" << endl;
      if (!R) cout << "UD" << endl;
    } else {
      cout << D + U + L + R << endl;
      while (L--) cout << 'L';
      while (D--) cout << 'D';
      while (R--) cout << 'R';
      while (U--) cout << 'U';
      cout << endl;
    }
  }
  return 0;
}
