#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int ntest;
  cin >> ntest;
  while (ntest--) {
    string s;
    cin >> s;
    vector<int> cnt(5, 0);
    for (auto u : s) {
      if (u == 'L') cnt[0]++;
      if (u == 'R') cnt[1]++;
      if (u == 'U') cnt[2]++;
      if (u == 'D') cnt[3]++;
    }
    if (cnt[0] == 0 || cnt[1] == 0) {
      cnt[0] = cnt[1] = 0;
      if (cnt[2] && cnt[3])
        cnt[2] = cnt[3] = 1;
      else
        cnt[2] = cnt[3] = 0;
      int sum = 0;
      for (int i = 0; i < 4; i++) sum += cnt[i];
      if (sum == 0) {
        cout << 0 << '\n';
        continue;
      } else {
        cout << 2 << '\n';
        cout << "UD\n";
        continue;
      }
    }
    if (cnt[2] == 0 || cnt[3] == 0) {
      cnt[2] = cnt[3] = 0;
      if (cnt[0] && cnt[1])
        cnt[0] = cnt[1] = 1;
      else
        cnt[0] = cnt[1] = 0;
      int sum = 0;
      for (int i = 0; i < 4; i++) sum += cnt[i];
      if (sum == 0) {
        cout << 0 << '\n';
        continue;
      } else {
        cout << 2 << '\n';
        cout << "LR\n";
        continue;
      }
    }
    int t1 = min(cnt[0], cnt[1]);
    int t2 = min(cnt[2], cnt[3]);
    cout << 2 * (t1 + t2) << '\n';
    for (int i = 1; i <= t2; i++) {
      cout << "U";
    }
    for (int i = 1; i <= t1; i++) {
      cout << "R";
    }
    for (int i = 1; i <= t2; i++) {
      cout << "D";
    }
    for (int i = 1; i <= t1; i++) {
      cout << "L";
    }
    cout << '\n';
  }
  return 0;
}
