#include <bits/stdc++.h>
using namespace std;
int T;
string S;
void Solve(string Path) {
  int up = 0, down = 0, left = 0, right = 0;
  for (int i = 0; i < Path.size(); ++i) {
    switch (Path[i]) {
      case 'U': {
        ++up;
        break;
      }
      case 'D': {
        ++down;
        break;
      }
      case 'L': {
        ++left;
        break;
      }
      default:
        ++right;
    }
  }
  int hori = min(left, right), vert = min(up, down);
  if (hori && vert) {
    cout << (hori + vert) * 2 << '\n';
    for (int i = 0; i < hori; ++i) cout << 'R';
    for (int i = 0; i < vert; ++i) cout << 'U';
    for (int i = 0; i < hori; ++i) cout << 'L';
    for (int i = 0; i < vert; ++i) cout << 'D';
  } else if (hori) {
    cout << "2" << '\n';
    cout << "LR";
  } else if (vert) {
    cout << "2" << '\n';
    cout << "UD";
  } else
    cout << "0" << '\n';
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> T;
  getline(cin, S);
  for (int i = 0; i < T; ++i) {
    getline(cin, S);
    Solve(S);
  }
  cout.flush();
}
