#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    int n, l = 0, r = 0, u = 0, d = 0;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'L')
        l++;
      else if (s[i] == 'R')
        r++;
      else if (s[i] == 'U')
        u++;
      else
        d++;
    }
    int a = min(l, r);
    int b = min(u, d);
    if (a == 0 && b == 0) {
      cout << 0 << endl;
    } else if (a == 0) {
      cout << 2 << endl;
      cout << "UD" << endl;
    } else if (b == 0) {
      cout << 2 << endl;
      cout << "LR" << endl;
    } else {
      cout << 2 * (a + b) << endl;
      for (int i = 0; i < a; i++) {
        cout << 'L';
      }
      for (int i = 0; i < b; i++) {
        cout << 'U';
      }
      for (int i = 0; i < a; i++) {
        cout << 'R';
      }
      for (int i = 0; i < b; i++) {
        cout << 'D';
      }
      cout << endl;
    }
  }
  return 0;
}
