#include <bits/stdc++.h>
using namespace std;
const long long M = 2e5 + 2, MOD = 1e9 + 7;
string s;
int arr[M], a[M];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, m, c, d = 0, sum = 0, t, b;
  cin >> t;
  while (t--) {
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      a[s[i] - 65]++;
    }
    int mx = min(a['U' - 65], a['D' - 65]);
    int mi = min(a['R' - 65], a['L' - 65]);
    a['U' - 65] = a['D' - 65] = a['R' - 65] = a['L' - 65] = 0;
    if (mx == 0 && mi == 0) {
      cout << 0 << endl;
    } else if (mx == 0 && mi > 0) {
      cout << 2 << endl;
      cout << "LR" << endl;
    } else if (mi == 0 && mx > 0) {
      cout << 2 << endl;
      cout << "UD" << endl;
    } else {
      cout << mx * 2 + mi * 2 << endl;
      for (int i = 0; i < mx; i++) cout << 'U';
      for (int i = 0; i < mi; i++) cout << 'R';
      for (int i = 0; i < mx; i++) cout << 'D';
      for (int i = 0; i < mi; i++) cout << 'L';
      cout << endl;
    }
  }
  return 0;
}
