#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long INF = 1e9 + 47;
const long long LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    map<char, int> mp;
    for (auto i : s) mp[i]++;
    int UD = min(mp['U'], mp['D']);
    int LR = min(mp['L'], mp['R']);
    if (UD == 0) LR = min(LR, 1);
    if (LR == 0) UD = min(UD, 1);
    cout << 2 * (UD + LR) << endl;
    for (int i = (0); i < (UD); ++i) cout << 'U';
    for (int i = (0); i < (LR); ++i) cout << 'R';
    for (int i = (0); i < (UD); ++i) cout << 'D';
    for (int i = (0); i < (LR); ++i) cout << 'L';
    cout << '\n';
  }
  cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}
