#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
int t, a[4];
map<char, int> mp;
string res;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> t;
  mp['L'] = 0;
  mp['R'] = 1;
  mp['U'] = 2;
  mp['D'] = 3;
  while (t--) {
    string s;
    res = "";
    cin >> s;
    a[0] = a[1] = a[2] = a[3] = 0;
    for (int i = (0); i <= (((int)(s).size()) - 1); ++i) a[mp[s[i]]]++;
    int h = min(a[2], a[3]), w = min(a[0], a[1]);
    if (h == 0 && w > 0) {
      cout << "2\nLR\n";
    } else if (w == 0 && h > 0)
      cout << "2\nUD\n";
    else {
      cout << h * 2 + w * 2 << '\n';
      for (int i = (1); i <= (h); ++i) res += 'U';
      for (int i = (1); i <= (w); ++i) res += 'R';
      for (int i = (1); i <= (h); ++i) res += 'D';
      for (int i = (1); i <= (w); ++i) res += 'L';
      cout << res << '\n';
    }
  }
}
