#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e9 + 1;
const int INF = (int)1e9 + 7;
const long long MAXSIZE = 400000;
void input() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long mod(long long x, long long m) { return (x % m + m) % m; }
int main() {
  input();
  int q;
  cin >> q;
  for (int pq = 0; pq < q; pq++) {
    string s;
    cin >> s;
    long long u = 0, l = 0, r = 0, d = 0;
    for (int i = 0; i < (int)s.size(); i++) {
      if (s[i] == 'U') u++;
      if (s[i] == 'R') r++;
      if (s[i] == 'L') l++;
      if (s[i] == 'D') d++;
    }
    if (min(u, d) == 0 && min(r, l) != 0) r = 1;
    if (min(r, l) == 0 && min(u, d) != 0) u = 1;
    cout << 2 * min(u, d) + 2 * min(r, l) << '\n';
    for (int i = 0; i < min(u, d); i++) cout << "U";
    for (int i = 0; i < min(r, l); i++) cout << "L";
    for (int i = 0; i < min(u, d); i++) cout << "D";
    for (int i = 0; i < min(r, l); i++) cout << "R";
    cout << endl;
  }
  return 0;
}
