#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  for (long long k = 0; k < n; k++) {
    string s;
    cin >> s;
    map<char, long long> m;
    for (char& i : s) m[i]++;
    long long r = min(m['R'], m['L']);
    long long c = min(m['U'], m['D']);
    if (r != 0 && c != 0) {
      cout << r * 2 + c * 2 << "\n";
      for (long long i = 0; i < r; i++) cout << 'R';
      for (long long i = 0; i < c; i++) cout << 'U';
      for (long long j = 0; j < r; j++) cout << 'L';
      for (long long j = 0; j < c; j++) cout << 'D';
      cout << "\n";
    } else if (c == 0 && r != 0) {
      cout << "2\nLR\n";
    } else if (r == 0 && c != 0) {
      cout << "2\nUD\n";
    } else
      cout << "0\n";
  }
  return 0;
}
