#include <bits/stdc++.h>
using namespace std;
void print(int n, char c) {
  for (int i = 0; i < n; i++) cout << c;
}
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string s;
    cin >> s;
    int l = 0, r = 0, u = 0, d = 0;
    for (int j = 0; j < s.size(); j++) switch (s[j]) {
        case 'L':
          l++;
          break;
        case 'R':
          r++;
          break;
        case 'U':
          u++;
          break;
        case 'D':
          d++;
          break;
      }
    l = min(l, r);
    r = min(l, r);
    u = min(u, d);
    d = min(u, d);
    if (l == 0 && u != 0) u = 1;
    if (u == 0 && l != 0) l = 1;
    cout << 2 * (l + u) << endl;
    print(l, 'L');
    print(u, 'U');
    print(l, 'R');
    print(u, 'D');
    cout << endl;
  }
}
