Recently you have bought a snow walking robot and brought it home. Suppose your home is a cell $(0, 0)$ on an infinite grid.

You also have the sequence of instructions of this robot. It is written as the string $s$ consisting of characters 'L', 'R', 'U' and 'D'. If the robot is in the cell $(x, y)$ right now, he can move to one of the adjacent cells (depending on the current instruction).  If the current instruction is 'L', then the robot can move to the left to $(x - 1, y)$;  if the current instruction is 'R', then the robot can move to the right to $(x + 1, y)$;  if the current instruction is 'U', then the robot can move to the top to $(x, y + 1)$;  if the current instruction is 'D', then the robot can move to the bottom to $(x, y - 1)$. 

You've noticed the warning on the last page of the manual: if the robot visits some cell (except $(0, 0)$) twice then it breaks.

So the sequence of instructions is valid if the robot starts in the cell $(0, 0)$, performs the given instructions, visits no cell other than $(0, 0)$ two or more times and ends the path in the cell $(0, 0)$. Also cell $(0, 0)$ should be visited at most two times: at the beginning and at the end (if the path is empty then it is visited only once). For example, the following sequences of instructions are considered valid: "UD", "RL", "UUURULLDDDDLDDRRUU", and the following are considered invalid: "U" (the endpoint is not $(0, 0)$) and "UUDD" (the cell $(0, 1)$ is visited twice).

The initial sequence of instructions, however, might be not valid. You don't want your robot to break so you decided to reprogram it in the following way: you will remove some (possibly, all or none) instructions from the initial sequence of instructions, then rearrange the remaining instructions as you wish and turn on your robot to move. 

Your task is to remove as few instructions from the initial sequence as possible and rearrange the remaining ones so that the sequence is valid. Report the valid sequence of the maximum length you can obtain.

Note that you can choose any order of remaining instructions (you don't need to minimize the number of swaps or any other similar metric).

You have to answer $q$ independent test cases.


-----Input-----

The first line of the input contains one integer $q$ ($1 \le q \le 2 \cdot 10^4$) — the number of test cases.

The next $q$ lines contain test cases. The $i$-th test case is given as the string $s$ consisting of at least $1$ and no more than $10^5$ characters 'L', 'R', 'U' and 'D' — the initial sequence of instructions.

It is guaranteed that the sum of $|s|$ (where $|s|$ is the length of $s$) does not exceed $10^5$ over all test cases ($\sum |s| \le 10^5$).


-----Output-----

For each test case print the answer on it. In the first line print the maximum number of remaining instructions. In the second line print the valid sequence of remaining instructions $t$ the robot has to perform. The moves are performed from left to right in the order of the printed sequence. If there are several answers, you can print any. If the answer is $0$, you are allowed to print an empty line (but you can don't print it).


-----Example-----
Input
6
LRU
DURLDRUDRULRDURDDL
LRUDDLRUDRUL
LLLLRRRR
URDUR
LLL

Output
2
LR
14
RUURDDDDLLLUUR
12
ULDDDRRRUULL
2
LR
2
UD
0




-----Note-----

There are only two possible answers in the first test case: "LR" and "RL".

The picture corresponding to the second test case: [Image] Note that the direction of traverse does not matter 

Another correct answer to the third test case: "URDDLLLUURDR".

Difficulty: EASY

Solutions:
t = int(input())
while t:
	s = input()
	(l, r, u, d) = (0, 0, 0, 0)
	for i in s:
		if i == 'U':
			u += 1
		if i == 'D':
			d += 1
		if i == 'R':
			r += 1
		if i == 'L':
			l += 1
	mlr = min(l, r)
	mud = min(u, d)
	l = mlr
	r = mlr
	u = mud
	d = mud
	if mud != 0 and mlr == 0:
		print(2)
		print('UD')
	elif mlr != 0 and mud == 0:
		print(2)
		print('LR')
	elif mlr == 0 and mud == 0:
		print(0)
		print()
	else:
		print(l + r + u + d)
		print('L' * l + 'U' * u + 'R' * r + 'D' * d)
	t -= 1


q = int(input())
for i in range(q):
	a = input()
	L = 0
	R = 0
	U = 0
	D = 0
	for j in range(len(a)):
		if a[j] == 'L':
			L += 1
		elif a[j] == 'R':
			R += 1
		elif a[j] == 'U':
			U += 1
		else:
			D += 1
	if L == 0 or R == 0:
		if U == 0 or D == 0:
			print(0)
		else:
			print(2)
			print('UD')
	elif U == 0 or D == 0:
		print(2)
		print('LR')
	else:
		x = min(L, R)
		y = min(U, D)
		print((x + y) * 2)
		print(x * 'L' + y * 'U' + x * 'R' + y * 'D')


t = int(input())
for nt in range(t):
	s = input()
	(l, r, u, d) = (0, 0, 0, 0)
	for i in s:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	if l != 0 and r != 0 and (u != 0) and (d != 0):
		if l == r and u == d:
			print(len(s))
			for i in range(l):
				print('L', end='')
			for i in range(u):
				print('U', end='')
			for i in range(l):
				print('R', end='')
			for i in range(d):
				print('D', end='')
		elif l == r:
			print(len(s) - abs(u - d))
			for i in range(l):
				print('L', end='')
			for i in range(min(d, u)):
				print('U', end='')
			for i in range(l):
				print('R', end='')
			for i in range(min(d, u)):
				print('D', end='')
		else:
			print(len(s) - (abs(u - d) + abs(l - r)))
			for i in range(min(l, r)):
				print('L', end='')
			for i in range(min(d, u)):
				print('U', end='')
			for i in range(min(l, r)):
				print('R', end='')
			for i in range(min(d, u)):
				print('D', end='')
		print()
	elif (l == 0 or r == 0) and (u != 0 and d != 0):
		print(2)
		print('UD')
	elif (u == 0 or d == 0) and (l != 0 and r != 0):
		print(2)
		print('LR')
	else:
		print(0)
		print()


for _ in range(int(input())):
	s = input()
	(l, r, u, d) = (s.count('L'), s.count('R'), s.count('U'), s.count('D'))
	(a, b) = (min(l, r), min(u, d))
	if a == 0 and b > 0:
		b = 1
	elif b == 0 and a > 0:
		a = 1
	print(2 * (a + b), 'L' * a + 'U' * b + 'R' * a + 'D' * b, sep='\n')


q = int(input())
for _ in range(q):
	s = input()
	d = {}
	for i in s:
		d[i] = d.get(i, 0) + 1
	ud = min(d.get('U', 0), d.get('D', 0))
	lr = min(d.get('L', 0), d.get('R', 0))
	if ud == 0:
		lr = min(lr, 1)
	elif lr == 0:
		ud = min(ud, 1)
	ans = 2 * (ud + lr)
	print(ans)
	print('L' * lr + 'U' * ud + 'R' * lr + 'D' * ud)


T = int(input())
for t in range(T):
	s = input()
	l = s.count('L')
	u = s.count('U')
	r = s.count('R')
	d = s.count('D')
	(l, r) = (min(l, r), min(l, r))
	(u, d) = (min(u, d), min(u, d))
	if l == 0 and u == 0:
		print('0')
		print('')
	elif l == 0:
		print('2')
		print('UD')
	elif u == 0:
		print('2')
		print('LR')
	else:
		s = ''
		s += 'L' * l + 'U' * u + 'R' * r + 'D' * d
		print(len(s))
		print(s)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import deque
from heapq import heappush, heappop
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
t = ip()
for _ in range(t):
	s = ips()
	ch = 'LRUD'
	dic = {}
	for i in ch:
		dic[i] = 0
	for i in s:
		dic[i] += 1
	if len(set(s)) == 1:
		print(0)
		print('')
	else:
		rmin = min(dic['L'], dic['R'])
		dmin = min(dic['U'], dic['D'])
		if rmin == 0 and dmin == 0:
			ans = 0
			print(ans)
			print('')
		elif rmin == 0 and dmin != 0:
			ans = 2
			print(ans)
			print('UD')
		elif rmin != 0 and dmin == 0:
			ans = 2
			print(ans)
			print('LR')
		else:
			ans = 2 * rmin + 2 * dmin
			ch = ''
			ch += 'L' * rmin + 'U' * dmin + 'R' * rmin + 'D' * dmin
			print(ans)
			print(ch)


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	S = input()
	C = Counter(S)
	if (C['L'] == 0 or C['R'] == 0) and (C['U'] == 0 or C['D'] == 0):
		print(0)
	elif C['L'] == 0 or C['R'] == 0:
		print(2)
		print('UD')
	elif C['U'] == 0 or C['D'] == 0:
		print(2)
		print('LR')
	else:
		lr = min(C['L'], C['R'])
		ud = min(C['U'], C['D'])
		print(lr * 2 + ud * 2)
		ans = ''
		ans += 'L' * lr
		ans += 'U' * ud
		ans += 'R' * lr
		ans += 'D' * ud
		print(ans)


import collections
t = int(input())
for i in range(t):
	s = list(input())
	c = collections.Counter(s)
	(L, R, U, D) = (c['L'], c['R'], c['U'], c['D'])
	if (L == 0 or R == 0) and (U == 0 or D == 0):
		print(0)
	elif L == 0 or R == 0:
		print(2)
		print('UD')
	elif U == 0 or D == 0:
		print(2)
		print('LR')
	else:
		(p, q) = (min(L, R), min(U, D))
		print(2 * p + 2 * q)
		print(p * 'L' + q * 'U' + p * 'R' + q * 'D')


for test in range(int(input())):
	s = input()
	a = {'L': 0, 'R': 0, 'D': 0, 'U': 0}
	for i in s:
		a[i] += 1
	m1 = min(a['L'], a['R'])
	m2 = min(a['U'], a['D'])
	if m1 == m2 == 0:
		print(0)
	elif m1 == 0:
		print(2)
		print('UD')
	elif m2 == 0:
		print(2)
		print('LR')
	else:
		print(m1 * 2 + m2 * 2)
		print('L' * m1 + 'U' * m2 + 'R' * m1 + 'D' * m2)


t = int(input())
for i in range(t):
	s = input()
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	a1 = 0
	a2 = 0
	s = ''
	if l > r:
		a1 += r
	elif l < r:
		a1 += l
	else:
		a1 += l
	if u > d:
		a2 += d
	elif u < d:
		a2 += u
	else:
		a2 += u
	if a1 == 0 and a2 == 0:
		s = ''
	elif a1 == 0 and a2 > 1:
		s += 'UD'
	elif a1 > 1 and a2 == 0:
		s += 'LR'
	else:
		s += 'L' * a1
		s += 'U' * a2
		s += 'R' * a1
		s += 'D' * a2
	print(len(s))
	print(s)


def generate_path(LR, UD):
	return ''.join(['L'] * LR + ['U'] * UD + ['R'] * LR + ['D'] * UD)
for _ in range(int(input())):
	L = 0
	R = 0
	U = 0
	D = 0
	for i in input():
		if i == 'L':
			L += 1
		elif i == 'R':
			R += 1
		elif i == 'U':
			U += 1
		else:
			D += 1
	LR = min(L, R)
	UD = min(U, D)
	if LR == 0 and UD == 0:
		print(0)
		print('')
	elif LR == 0:
		print(2)
		print(generate_path(0, 1))
	elif UD == 0:
		print(2)
		print(generate_path(1, 0))
	else:
		print(2 * (LR + UD))
		print(generate_path(LR, UD))


n = int(input())
for i in range(n):
	s = input()
	b = s.count('L')
	c = s.count('R')
	d = s.count('U')
	e = s.count('D')
	minn1 = min(b, c)
	minn2 = min(d, e)
	if minn1 == 0 and minn2 >= 1:
		print(2)
		print('UD')
	elif minn2 == 0 and minn1 >= 1:
		print(2)
		print('LR')
	else:
		m = 'L' * minn1 + 'U' * minn2 + 'R' * minn1 + 'D' * minn2
		print(len(m))
		print(m)


n = int(input())
for i in range(n):
	cnts = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	inp = input()
	for g in inp:
		cnts[g] += 1
	bf = list(cnts.keys())
	cnts = list(cnts.values())
	cnts[0] = min(cnts[0], cnts[1])
	cnts[1] = min(cnts[0], cnts[1])
	cnts[2] = min(cnts[2], cnts[3])
	cnts[3] = min(cnts[2], cnts[3])
	if cnts[0] > 0 and cnts[2] > 0:
		print(sum(cnts))
		print(bf[0] * cnts[0], end='')
		print(bf[2] * cnts[2], end='')
		print(bf[1] * cnts[1], end='')
		print(bf[3] * cnts[3], end='')
	elif cnts[0] > 0:
		print(2)
		print('LR', end='')
	elif cnts[2] > 0:
		print(2)
		print('UD', end='')
	else:
		print(0)
	print()


for _ in range(int(input())):
	s = input()
	d = s.count('D')
	u = s.count('U')
	r = s.count('R')
	l = s.count('L')
	x = min(d, u)
	(d, u) = (x, x)
	x = min((r, l))
	(r, l) = (x, x)
	ans = 'L' * l + 'U' * u + 'R' * r + 'D' * d
	if d == 0 and u == 0:
		if l > 1 and r > 1:
			ans = 'LR'
	elif l == 0 and r == 0:
		if u > 1 and d > 1:
			ans = 'UD'
	print(len(ans))
	print(ans)


for i in range(int(input())):
	s = input()
	ans = 0
	ans2 = 0
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	if (l == 0 or r == 0) and (u == 0 or d == 0):
		print(0)
	elif l == 0 or r == 0:
		print(2)
		print('UD')
	elif u == 0 or d == 0:
		print(2)
		print('LR')
	else:
		ans = min(l, r)
		ans2 = min(u, d)
		print(2 * (ans + ans2))
		print('L' * ans + 'U' * ans2 + 'R' * ans + 'D' * ans2)


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
for _ in range(inn()):
	s = input()
	ans = ''
	d = defaultdict(int)
	for i in s:
		d[i] += 1
	mn1 = min(d['L'], d['R'])
	mn2 = min(d['U'], d['D'])
	if mn1 > 0 and mn2 > 0:
		ans = 'L' * mn1 + 'U' * mn2 + 'R' * mn1 + 'D' * mn2
	elif mn1 > 0:
		ans = 'LR'
	elif mn2 > 0:
		ans = 'UD'
	print(len(ans))
	print(ans)


for _ in range(int(input())):
	s = input()
	n = len(s)
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	if min(l, r) == 0 and min(u, d) == 0:
		print(0)
	elif min(l, r) == 0:
		print('2\nUD')
	elif min(u, d) == 0:
		print('2\nLR')
	else:
		ans = min(l, r) + min(u, d)
		print(2 * ans)
		s = ''
		for i in range(min(l, r)):
			s += 'L'
		for i in range(min(u, d)):
			s += 'U'
		for i in range(min(l, r)):
			s += 'R'
		for i in range(min(u, d)):
			s += 'D'
		print(s)


t = int(input())
for test in range(t):
	s = input()
	(L, R, D, U) = (0, 0, 0, 0)
	for c in s:
		if c == 'L':
			L += 1
		elif c == 'R':
			R += 1
		elif c == 'U':
			U += 1
		else:
			D += 1
	(vert, oriz) = (min(U, D), min(L, R))
	if vert == oriz == 0:
		print('0\n\n', end='')
	elif vert == 0:
		print('2\nLR\n', end='')
	elif oriz == 0:
		print('2\nUD\n', end='')
	else:
		print(2 * (vert + oriz))
		for i in range(oriz):
			print('L', end='')
		for i in range(vert):
			print('U', end='')
		for i in range(oriz):
			print('R', end='')
		for i in range(vert):
			print('D', end='')
		print()


from sys import stdin
op = {'R': 'L', 'L': 'R', 'D': 'U', 'U': 'D'}
no = {'R': 'D', 'L': 'D', 'D': 'L', 'U': 'L'}
from collections import Counter
t = int(input())
for i in range(t):
	s = input()
	c = Counter(s)
	ans = 0
	route = ''
	if min(c['R'], c['L']) == 0:
		if min(c['D'], c['U']) >= 1:
			ans = len(s) - 2
			route = 'UD'
		else:
			ans = len(s)
	elif min(c['D'], c['U']) == 0:
		if min(c['L'], c['R']) >= 1:
			ans = len(s) - 2
			route = 'LR'
		else:
			ans = len(s)
	else:
		ans += abs(c['R'] - c['L']) + abs(c['D'] - c['U'])
		route += min(c['R'], c['L']) * 'L'
		route += min(c['D'], c['U']) * 'U'
		route += min(c['R'], c['L']) * 'R'
		route += min(c['D'], c['U']) * 'D'
	ans = len(s) - ans
	print(ans)
	print(route)


for _ in range(int(input())):
	s = str(input())
	d = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for i in s:
		d[i] += 1
	l = min(d['L'], d['R'])
	b = min(d['U'], d['D'])
	p = 0
	if l != 0 and b != 0:
		p = 2 * (l + b)
		ans = 'L' * l + 'U' * b + 'R' * l + 'D' * b
	elif l == 0 and b != 0:
		p = 2
		ans = 'UD'
	elif l != 0 and b == 0:
		p = 2
		ans = 'LR'
	else:
		p = 0
		ans = ''
	print(p)
	print(ans)


for _ in range(int(input())):
	s = input()
	l = 0
	r = 0
	u = 0
	d = 0
	for elem in s:
		if elem == 'U':
			u += 1
		elif elem == 'D':
			d += 1
		elif elem == 'L':
			l += 1
		else:
			r += 1
	l_r = min(l, r)
	u_d = min(u, d)
	if u_d == 0 and l_r != 0:
		print(2)
		print('LR')
	elif l_r == 0 and u_d != 0:
		print(2)
		print('UD')
	else:
		ans = 'L' * l_r + 'U' * u_d + 'R' * l_r + 'D' * u_d
		print(len(ans))
		print(ans)


for q in range(int(input())):
	s = input()
	d = {}
	moves = 'LRUD'
	for i in moves:
		if i not in d:
			d[i] = 0
	for i in s:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	v = min(d['U'], d['D'])
	h = min(d['L'], d['R'])
	if min(v, h) == 0:
		if v == 0:
			if h == 0:
				print(0)
			else:
				print(2)
				print('LR')
		elif v == 0:
			print(0)
		else:
			print(2)
			print('UD')
	else:
		res = ''
		res += 'L' * h
		res += 'U' * v
		res += 'R' * h
		res += 'D' * v
		print(len(res))
		print(res)


q = int(input())
for _ in range(q):
	s = input()
	(u, r, d, l) = (0, 0, 0, 0)
	for i in s:
		if i == 'U':
			u += 1
		elif i == 'R':
			r += 1
		elif i == 'D':
			d += 1
		else:
			l += 1
	if min(l, r) == 0:
		u = min(1, u)
		d = min(1, d)
	if min(u, d) == 0:
		l = min(1, l)
		r = min(1, r)
	ans = 'L' * min(l, r) + 'U' * min(u, d) + 'R' * min(l, r) + 'D' * min(u, d)
	print(len(ans))
	print(ans)


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
for _ in range(ii()):
	s = si()
	(l, r, u, d) = (s.count('L'), s.count('R'), s.count('U'), s.count('D'))
	(l, r) = (min(l, r), min(l, r))
	(u, d) = (min(u, d), min(u, d))
	if l == 0:
		if u == 0:
			print(0)
		else:
			print(2)
			print('UD')
	elif u == 0:
		print(2)
		print('LR')
	else:
		print(l + r + u + d)
		print('L' * l + 'U' * u + 'R' * r + 'D' * d)


t = int(input())
for i in range(0, t):
	s = input()
	lcount = 0
	rcount = 0
	ucount = 0
	dcount = 0
	for j in s:
		if j == 'L':
			lcount += 1
		elif j == 'R':
			rcount += 1
		elif j == 'U':
			ucount += 1
		elif j == 'D':
			dcount += 1
	lr = min(lcount, rcount)
	ud = min(ucount, dcount)
	if lr == 0 and ud == 0:
		print(0)
	elif lr == 0:
		ss = ''
		for j in range(0, 1):
			ss += 'U'
		for j in range(0, 1):
			ss += 'D'
		print(len(ss))
		print(ss)
	elif ud == 0:
		ss = ''
		for j in range(0, 1):
			ss += 'L'
		for j in range(0, 1):
			ss += 'R'
		print(len(ss))
		print(ss)
	else:
		ss = ''
		for j in range(0, lr):
			ss += 'L'
		for j in range(0, ud):
			ss += 'U'
		for j in range(0, lr):
			ss += 'R'
		for j in range(0, ud):
			ss += 'D'
		print(len(ss))
		print(ss)


for _ in range(int(input())):
	x = input()
	(L, R, U, P) = (x.count('L'), x.count('R'), x.count('U'), x.count('D'))
	if not (L > 0 and R > 0 or (U > 0 and P > 0)):
		print(0)
	elif L > 0 and R > 0 and (U > 0) and (P > 0):
		(h, v) = (min(L, R), min(U, P))
		print(2 * h + 2 * v)
		print('L' * h + 'U' * v + 'R' * h + 'D' * v)
	else:
		print(2)
		print('L' + 'R' if L > 0 and R > 0 else 'U' + 'D')


for i in range(int(input())):
	p = input()
	left = p.count('L')
	right = p.count('R')
	up = p.count('U')
	down = p.count('D')
	upmoves = min(up, down)
	sidemoves = min(left, right)
	if min(sidemoves, upmoves) == 0:
		if sidemoves == 0:
			temp = min(upmoves, 1)
			print(2 * temp)
			print('U' * temp + 'D' * temp)
		else:
			temp = min(sidemoves, 1)
			print(2 * temp)
			print('L' * temp + 'R' * temp)
	else:
		answer = ''
		answer += 'L' * sidemoves
		answer += 'U' * upmoves
		answer += 'R' * sidemoves
		answer += 'D' * upmoves
		print(len(answer))
		print(answer)


t = int(input())
for i in range(t):
	seq = input()
	valid = []
	l = 0
	r = 0
	u = 0
	d = 0
	for i in seq:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	l = min(l, r)
	r = l
	u = min(u, d)
	d = u
	if u == 0:
		if l > 1:
			l = 1
			r = 1
	if l == 0:
		if u > 1:
			u = 1
			d = 1
	total = l + r + u + d
	print(total)
	for i in range(l):
		print('L', end='')
	for i in range(u):
		print('U', end='')
	for i in range(r):
		print('R', end='')
	for i in range(d):
		print('D', end='')
	print()


from sys import stdin, stdout
n = int(stdin.readline().strip())
for i in range(n):
	s = stdin.readline().strip()
	l = 0
	r = 0
	u = 0
	d = 0
	for i in range(len(s)):
		if s[i] == 'L':
			l += 1
		elif s[i] == 'R':
			r += 1
		elif s[i] == 'D':
			d += 1
		else:
			u += 1
	x = min(l, r)
	y = min(u, d)
	if y == 0:
		x = min(x, 1)
	if x == 0:
		y = min(y, 1)
	ans = ''
	for i in range(x):
		ans += 'L'
	for i in range(y):
		ans += 'U'
	for i in range(x):
		ans += 'R'
	for i in range(y):
		ans += 'D'
	print(len(ans))
	print(ans)


t = int(input())
import collections as c
for _ in range(t):
	a = list(input())
	b = c.Counter(a)
	if len(b) < 2:
		print('0')
	elif len(b) == 4:
		d1 = b['L']
		d2 = b['U']
		for i in b:
			if i == 'L' or i == 'R':
				d1 = min(d1, b[i])
			if i == 'U' or i == 'D':
				d2 = min(d2, b[i])
		s = 'L' * d1 + 'U' * d2 + 'R' * d1 + 'D' * d2
		print(len(s))
		print(s)
	elif 'L' in b and 'R' in b:
		print('2')
		print('LR')
	elif 'U' in b and 'D' in b:
		print('2')
		print('UD')
	else:
		print('0')


I = input
for _ in range(int(I())):
	s = list(I())
	d = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for i in s:
		d[i] += 1
	a = min(d['L'], d['R'])
	b = min(d['D'], d['U'])
	ans = ''
	ans += 'L' * a + 'U' * b + 'R' * a + 'D' * b
	if a == 0 and b > 1 or (b == 0 and a > 1):
		print(2)
		if a > 1:
			ans = 'LR'
		else:
			ans = 'UD'
	else:
		print(a * 2 + b * 2)
	print(ans)


from sys import stdin, stdout
import math
input = stdin.readline

def print(x='', y='', end='\n'):
	if y == '':
		stdout.write(str(x) + end)
	else:
		stdout.write(str(x) + ' ' + str(y) + end)

def solve():
	s = input()
	l = len(s)
	(c1, c2, c3, c4) = (s.count('L'), s.count('R'), s.count('U'), s.count('D'))
	ud = min(c3, c4)
	if ud == 0:
		if c1 >= 1 and c2 >= 1:
			print(2)
			print('LR')
		else:
			print(0)
	else:
		lr = min(c1, c2)
		if lr == 0:
			print(2)
			print('UD')
			return
		print(2 * (lr + ud))
		print('L' * lr + ud * 'U' + lr * 'R' + ud * 'D')
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


from collections import Counter
q = int(input())
for _ in range(q):
	s = input()
	char_counter = Counter(s)
	char_counter.setdefault('L', 0)
	char_counter.setdefault('R', 0)
	char_counter.setdefault('U', 0)
	char_counter.setdefault('D', 0)
	char_counter['L'] = min(char_counter['L'], char_counter['R'])
	char_counter['R'] = min(char_counter['L'], char_counter['R'])
	char_counter['U'] = min(char_counter['U'], char_counter['D'])
	char_counter['D'] = min(char_counter['U'], char_counter['D'])
	if char_counter['U'] == 0:
		if char_counter['L'] == 0:
			print(0)
		else:
			print(2)
			print('LR')
	elif char_counter['R'] == 0:
		if char_counter['U'] == 0:
			print(0)
		else:
			print(2)
			print('UD')
	else:
		ans = 'L' * char_counter['L']
		ans += 'U' * char_counter['U']
		ans += 'R' * char_counter['R']
		ans += 'D' * char_counter['D']
		print(len(ans))
		print(ans)


from collections import Counter
t = int(input())
for _ in range(t):
	s = input()
	count = Counter(s)
	keys = count.keys()
	min1 = min(count['L'], count['R'])
	min2 = min(count['U'], count['D'])
	if min2 == 0 and min1 != 0:
		min1 = 1
	if min1 == 0 and min2 != 0:
		min2 = 1
	s1 = 'L' * min1
	s1 += 'U' * min2
	s1 += 'R' * min1
	s1 += 'D' * min2
	print(len(s1))
	print(s1)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	left = 0
	right = 0
	up = 0
	down = 0
	for i in s:
		if i == 'L':
			left += 1
		elif i == 'R':
			right += 1
		elif i == 'U':
			up += 1
		else:
			down += 1
	minSide = min(left, right)
	minUp = min(up, down)
	if minSide == 0:
		if minUp > 0:
			print('2')
			print('UD')
		else:
			print('0')
			print()
	elif minUp == 0:
		if minSide > 0:
			print('2')
			print('LR')
		else:
			print('0')
			print()
	else:
		print(minSide * 2 + minUp * 2)
		s = 'L' * minSide + 'U' * minUp + 'R' * minSide + 'D' * minUp
		print(s)


t = int(input())
for _ in range(t):
	string = input()
	n = len(string)
	count = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	anscount = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	flag = False
	for i in range(n):
		count[string[i]] += 1
	while True:
		if count['L'] > 0 and count['R'] > 0 and (count['U'] > 0) and (count['D'] > 0):
			temp = min(count.values())
			anscount['L'] += temp
			anscount['R'] += temp
			anscount['U'] += temp
			anscount['D'] += temp
			count['L'] -= temp
			count['R'] -= temp
			count['U'] -= temp
			count['D'] -= temp
		else:
			if not flag:
				if count['U'] == 0 or count['D'] == 0:
					temp = min(count['L'], count['R'])
					if temp == 0:
						print(0)
						print()
					else:
						print(2)
						print('LR')
				elif count['L'] == 0 or count['R'] == 0:
					temp = min(count['U'], count['D'])
					if temp == 0:
						print(0)
						print()
					else:
						print(2)
						print('UD')
			elif count['U'] == 0 or count['D'] == 0:
				temp = min(count['L'], count['R'])
				if temp == 0:
					pass
				else:
					anscount['L'] += temp
					anscount['R'] += temp
					count['L'] -= temp
					count['R'] -= temp
			elif count['L'] == 0 or count['R'] == 0:
				temp = min(count['U'], count['D'])
				if temp == 0:
					pass
				else:
					anscount['U'] += temp
					anscount['D'] += temp
					count['U'] -= temp
					count['D'] -= temp
			break
		flag = True
	if flag:
		print(anscount['L'] + anscount['R'] + anscount['U'] + anscount['D'])
		print('L' * anscount['L'] + 'U' * anscount['U'] + 'R' * anscount['R'] + 'D' * anscount['D'])


import os
import sys
import bisect
from math import gcd, ceil
from heapq import heapify, heappop, heappush
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		ins = input()
		d = {}
		for x in ins:
			d[x] = d.get(x, 0) + 1
		lr = min(d.get('L', 0), d.get('R', 0))
		ud = min(d.get('U', 0), d.get('D', 0))
		if lr == 0 or ud == 0:
			lr = min(1, lr)
			ud = min(1, ud)
			if lr == 1 or ud == 1:
				print(2 * (lr + ud))
				print('L' * lr + 'U' * ud + 'R' * lr + 'D' * ud)
			else:
				print(0)
		else:
			print(2 * (lr + ud))
			print('L' * lr + 'U' * ud + 'R' * lr + 'D' * ud)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = lambda s: self.buffer.write(s.encode()) if self.writable else None

	def read(self):
		if self.buffer.tell():
			return self.buffer.read().decode('ascii')
		return os.read(self._fd, os.fstat(self._fd).st_size).decode('ascii')

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline().decode('ascii')

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

def print(*args, sep=' ', end='\n', file=sys.stdout, flush=False):
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(end)
	if flush:
		file.flush()
(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(10000)
main()


test = eval(input())
arr = []
for i in range(test):
	lst = input()
	arr.append(lst)
ans = []
ans2 = []
for lst in arr:
	(l, r, u, d) = (0, 0, 0, 0)
	path = [0] * 2
	for i in lst:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	if l < r:
		r = l
	else:
		l = r
	if u < d:
		d = u
	else:
		u = d
	if l == 0 and u != 0 or (l != 0 and u == 0):
		if l == 0:
			path = [0, 0, 1, 1]
		else:
			path = [1, 1, 0, 0]
		ans2.append(path)
		ans.append(2)
	else:
		path = [l, r, u, d]
		ans2.append(path)
		ans.append(l + r + u + d)
for i in range(len(ans)):
	print(ans[i])
	path = ''
	direct = ans2[i]
	l = 'L' * direct[0]
	r = 'R' * direct[1]
	u = 'U' * direct[2]
	d = 'D' * direct[3]
	path = l + u + r + d
	print(path)


for _ in range(int(input())):
	s = str(input())
	steps = [0, 0, 0, 0]
	for i in s:
		if i == 'L':
			steps[0] += 1
		elif i == 'R':
			steps[1] += 1
		elif i == 'U':
			steps[2] += 1
		else:
			steps[3] += 1
	(a, b, c, d) = (steps[0], steps[1], steps[2], steps[3])
	(t1, t2) = (min(a, b), min(c, d))
	if t1 < 1 and t2:
		t2 = 1
	if t2 < 1 and t1:
		t1 = 1
	print(2 * (t1 + t2))
	print('L' * t1 + 'U' * t2 + 'R' * t1 + 'D' * t2)


q = int(input())
for _ in range(q):
	d = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	s = input()
	for c in s:
		d[c] += 1
	if d['L'] != 0 and d['R'] != 0 and (min(d['U'], d['D']) == 0):
		print('2')
		print('LR')
	elif d['U'] != 0 and d['D'] != 0 and (min(d['L'], d['R']) == 0):
		print('2')
		print('UD')
	else:
		print(min(d['L'], d['R']) + min(d['U'], d['D']) + min(d['L'], d['R']) + min(d['U'], d['D']))
		print('L' * min(d['L'], d['R']) + 'U' * min(d['U'], d['D']) + 'R' * min(d['L'], d['R']) + 'D' * min(d['U'], d['D']))


for _ in [0] * int(input()):
	L = 0
	R = 0
	U = 0
	D = 0
	S = input()
	for i in S:
		if i == 'L':
			L += 1
		elif i == 'R':
			R -= 1
		elif i == 'U':
			U += 1
		elif i == 'D':
			D -= 1
	LR = min(L, -R)
	UD = min(U, -D)
	if LR == 0 and UD == 0:
		print(0)
	elif LR == 0 and UD > 0:
		print(2)
		print('UD')
	elif UD == 0 and LR > 0:
		print(2)
		print('LR')
	else:
		print(LR * 2 + UD * 2)
		ans = ''
		for i in range(LR):
			ans += 'L'
		for i in range(UD):
			ans += 'U'
		for i in range(LR):
			ans += 'R'
		for i in range(UD):
			ans += 'D'
		print(ans)


import sys
input = sys.stdin.readline
from collections import *
q = int(input())
for _ in range(q):
	s = input()[:-1]
	(L, R, U, D) = (0, 0, 0, 0)
	for si in s:
		if si == 'L':
			L += 1
		elif si == 'R':
			R += 1
		elif si == 'U':
			U += 1
		else:
			D += 1
	if min(L, R) == 0 and min(U, D) == 0:
		ans = ''
	elif min(L, R) == 0:
		ans = 'UD'
	elif min(U, D) == 0:
		ans = 'LR'
	else:
		ans = 'L' * min(L, R) + 'U' * min(U, D) + 'R' * min(L, R) + 'D' * min(U, D)
	print(len(ans))
	print(ans)


for _ in range(int(input())):
	s = str(input())
	(l, r, u, d) = (0, 0, 0, 0)
	for i in s:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		elif i == 'D':
			d += 1
	if u == 0 or d == 0:
		if r != 0 and l != 0:
			print(2)
			print('LR')
		else:
			print(0)
	elif r == 0 or l == 0:
		if u != 0 and d != 0:
			print(2)
			print('UD')
		else:
			print(0)
	else:
		left = min(l, r)
		up = min(u, d)
		print(2 * left + 2 * up)
		for i in range(left):
			print('L', end='')
		for i in range(up):
			print('U', end='')
		for i in range(left):
			print('R', end='')
		for i in range(up):
			print('D', end='')
		print()


for _ in ' ' * int(input()):
	z = input()
	k = min(z.count('L'), z.count('R'))
	k1 = min(z.count('U'), z.count('D'))
	if k == 0:
		if k1:
			print(2)
			print('UD')
		else:
			print(0)
	elif k1 == 0:
		if k:
			print(2)
			print('LR')
		else:
			print(0)
	else:
		print(2 * k + 2 * k1)
		print('L' * k + 'U' * k1 + 'R' * k + 'D' * k1)


for _ in range(int(input())):
	s = input()
	u = s.count('U')
	d = s.count('D')
	l = s.count('L')
	r = s.count('R')
	(ud, lr) = (min(u, d), min(l, r))
	if ud == lr == 0:
		print(0)
	elif ud == 0:
		print(2)
		print('LR')
	elif lr == 0:
		print(2)
		print('UD')
	else:
		print(2 * (ud + lr))
		print(lr * 'L' + ud * 'U' + lr * 'R' + ud * 'D')


q = int(input())
while q > 0:
	no = [0, 0, 0, 0]
	com = list(input())
	for i in com:
		if i == 'R':
			no[0] += 1
		elif i == 'L':
			no[1] += 1
		elif i == 'U':
			no[2] += 1
		elif i == 'D':
			no[3] += 1
	no[0] = min(no[0], no[1])
	no[2] = min(no[2], no[3])
	if no[0] == 0:
		if no[2] > 0:
			print('2\nUD')
		else:
			print('0')
	elif no[2] == 0:
		if no[0] > 0:
			print('2\nLR')
		else:
			print('0')
	else:
		print(no[0] * 2 + no[2] * 2)
		for i in range(0, no[0]):
			print('L', end='')
		for i in range(0, no[2]):
			print('U', end='')
		for i in range(0, no[0]):
			print('R', end='')
		for i in range(0, no[2]):
			print('D', end='')
		print('')
	q -= 1


from collections import Counter
q = int(input())
for _ in range(q):
	s = input()
	count = Counter()
	for e in s:
		count[e] += 1
	LR = min(count['L'], count['R'])
	UD = min(count['U'], count['D'])
	if LR == 0:
		if UD >= 1:
			print(2)
			print('UD')
		else:
			print(0)
	elif UD == 0:
		if LR >= 1:
			print(2)
			print('LR')
	else:
		print(LR * 2 + UD * 2)
		print('L' * LR + 'U' * UD + 'R' * LR + 'D' * UD)


nos = int(input())
for mmm in range(nos):
	instruction = input()
	left = instruction.count('L')
	right = instruction.count('R')
	up = instruction.count('U')
	down = instruction.count('D')
	lr = min(left, right)
	ud = min(up, down)
	if lr == 0 and ud == 0:
		print(0)
		print('')
	elif min(lr, ud) == 0:
		print(2)
		if lr > 0:
			print('LR')
		else:
			print('UD')
	else:
		print(2 * (lr + ud))
		for i in range(lr):
			print('L', end='')
		for i in range(ud):
			print('U', end='')
		for i in range(lr):
			print('R', end='')
		for i in range(ud):
			print('D', end='')
		print()


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input().strip()
t = I()
for i in range(0, t):
	s = S()
	d = Counter(s)
	a = min(d['L'], d['R'])
	b = min(d['U'], d['D'])
	if b == 0:
		if d['L'] >= 1 and d['R'] >= 1:
			print(2)
			print('LR')
			continue
	if a == 0:
		if d['U'] >= 1 and d['D'] >= 1:
			print(2)
			print('UD')
			continue
	print(2 * a + 2 * b)
	print('L' * a + 'U' * b + 'R' * a + 'D' * b)


def sol(strin):
	let = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for v in strin:
		let[v] += 1
	a = min(let['L'], let['R'])
	b = min(let['D'], let['U'])
	if a == 0:
		b = min(b, 1)
	if b == 0:
		a = min(a, 1)
	return (a, b)
n = int(input().strip())
for i in range(n):
	strin = input().strip()
	(l, u) = sol(strin)
	print(str(l * 2 + u * 2) + '\n' + 'L' * l + 'U' * u + 'R' * l + 'D' * u)


from collections import defaultdict
for _ in range(int(input())):
	s = list(input())
	visited = dict()
	visited = defaultdict(lambda : False, visited)
	right = 0
	left = 0
	up = 0
	down = 0
	for i in s:
		if i == 'L':
			left += 1
		if i == 'R':
			right += 1
		if i == 'U':
			up += 1
		if i == 'D':
			down += 1
	if (left == 0 or right == 0) and (up > 0 and down > 0):
		print(2)
		print('UD')
	elif (up == 0 or down == 0) and (left > 0 and right > 0):
		print(2)
		print('LR')
	else:
		p = min(left, right)
		q = min(up, down)
		print(2 * (p + q))
		print('L' * p + 'U' * q + 'R' * p + 'D' * q)


t = int(input())
for _ in range(t):
	cnt = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for c in input():
		cnt[c] += 1
	(a, b) = (min(cnt['L'], cnt['R']), min(cnt['U'], cnt['D']))
	if b < 1 and a > 0:
		a = 1
	if a < 1 and b > 0:
		b = 1
	print(2 * (a + b))
	print('L' * a + 'U' * b + 'R' * a + 'D' * b)


test_count = int(input())
for _ in range(test_count):
	str = input()
	ch_cnt = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	for ch in str:
		ch_cnt[ch] += 1
	L_cnt = min(ch_cnt['L'], ch_cnt['R'])
	U_cnt = min(ch_cnt['U'], ch_cnt['D'])
	if L_cnt == 0 and U_cnt > 1:
		print(2)
		print('UD')
	elif L_cnt > 1 and U_cnt == 0:
		print(2)
		print('LR')
	else:
		print(2 * (L_cnt + U_cnt))
		print('L' * L_cnt + 'U' * U_cnt + 'R' * L_cnt + 'D' * U_cnt)


import sys
input = sys.stdin.readline
import collections

def main():
	t = int(input())
	for _ in range(t):
		S = input().strip()
		c = collections.Counter(S)
		x = min(c['L'], c['R'])
		y = min(c['U'], c['D'])
		if y == 0 and x == 0:
			print(0)
		elif y == 0 or x == 0:
			print(2)
			if x == 0:
				print('UD')
			else:
				print('LR')
		else:
			print((x + y) * 2)
			print('L' * x + 'U' * y + 'R' * x + 'D' * y)
main()


t = int(input())
for i in range(t):
	l1 = list(input())
	l = l1.count('L')
	r = l1.count('R')
	u = l1.count('U')
	d = l1.count('D')
	count = 0
	l = min(l, r)
	r = min(l, r)
	u = min(u, d)
	d = min(u, d)
	if l == 0 and u != 0:
		u = d = 1
	if u == 0 and l != 0:
		l = r = 1
	count = l + r + u + d
	print(count)
	print('L' * l, 'U' * u, 'R' * l, 'D' * u, sep='')


for _ in range(int(input())):
	rem = 0
	ans = ''
	lCount = rCount = uCount = dCount = 0
	s = input()
	for var in s:
		if var == 'L':
			lCount += 1
		elif var == 'R':
			rCount += 1
		elif var == 'U':
			uCount += 1
		else:
			dCount += 1
	L = min(lCount, rCount)
	R = min(uCount, dCount)
	if L == 0 and R == 0:
		ans = ''
	elif L != 0 and R == 0:
		ans = 'LR'
	elif L == 0 and R != 0:
		ans = 'UD'
	else:
		ans = 'L' * min(lCount, rCount) + 'U' * min(uCount, dCount) + 'R' * min(lCount, rCount) + 'D' * min(uCount, dCount)
	print(len(ans))
	print(ans)


def pt(a, b):
	while a > 0:
		print(b, end='')
		a -= 1

def main():
	t = int(input())
	for i in range(t):
		s = input()
		L = s.count('L')
		R = s.count('R')
		U = s.count('U')
		D = s.count('D')
		if L * R == 0 and U * D == 0:
			print('0\n')
		else:
			LR = min(L, R)
			UD = min(U, D)
			if LR == 0:
				print(2)
				print('UD')
			elif UD == 0:
				print(2)
				print('LR')
			else:
				print(LR * 2 + UD * 2)
				pt(LR, 'L')
				pt(UD, 'U')
				pt(LR, 'R')
				pt(UD, 'D')
				print('')
main()


for _ in range(int(input())):
	s = input()
	(l, r, u, d) = map(s.count, 'LRUD')
	h = min(l, r)
	v = min(u, d)
	if h == 0 and v == 0:
		print(0, '', sep='\n')
	elif h == 0:
		print(2, 'UD', sep='\n')
	elif v == 0:
		print(2, 'LR', sep='\n')
	else:
		print(2 * (v + h), 'L' * h + 'U' * v + 'R' * h + 'D' * v, sep='\n')


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
for _ in range(ii()):
	s = input()
	(L, R, U, D) = (s.count('L'), s.count('R'), s.count('U'), s.count('D'))
	L = R = min(L, R)
	U = D = min(U, D)
	if U == 0:
		L = R = min(L, 1)
	if L == 0:
		U = D = min(U, 1)
	print((L + U) * 2)
	print('L' * L + 'U' * U + 'R' * R + 'D' * D)


from collections import Counter
cases = int(input())
for q in range(cases):
	s = input()
	s = Counter(s)
	non_zeros = [i for i in s if s[i] != 0]
	if len(non_zeros) == 1:
		print(0)
		print()
	elif len(non_zeros) < 4:
		if 'L' in non_zeros and 'R' in non_zeros:
			print(2)
			print('LR')
		elif 'U' in non_zeros and 'D' in non_zeros:
			print(2)
			print('UD')
		else:
			print(0)
			print()
	else:
		v1 = min(s['L'], s['R'])
		v2 = min(s['U'], s['D'])
		print(2 * v1 + 2 * v2)
		print('L' * v1 + 'U' * v2 + 'R' * v1 + 'D' * v2)


n = int(input())
for i in range(n):
	seq = input()
	d = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	l = []
	for s in seq:
		d[s] += 1
	ud = min(d['U'], d['D'])
	lr = min(d['L'], d['R'])
	if ud == 0 and lr > 0:
		lr = 1
	elif ud > 0 and lr == 0:
		ud = 1
	print(lr * 2 + ud * 2)
	s = ''
	s = s + 'L' * lr
	s = s + 'U' * ud
	s = s + 'R' * lr
	s = s + 'D' * ud
	print(s)


for _ in range(int(input())):
	s = list(input())
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	x = min(l, r)
	y = min(u, d)
	if x == 0 and y != 0:
		print(2)
		print('UD')
		continue
	if x != 0 and y == 0:
		print(2)
		print('LR')
		continue
	print(2 * (x + y))
	print('L' * x + 'U' * y + 'R' * x + 'D' * y)


def main():
	buf = input()
	q = int(buf)
	s = []
	n = []
	for t in range(q):
		buf = input()
		s.append(buf)
		n.append(len(s[t]))
	ans = []
	for t in range(q):
		c = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
		for i in range(n[t]):
			c[s[t][i]] += 1
		lr_min = min(c['L'], c['R'])
		ud_min = min(c['U'], c['D'])
		if lr_min == 0 and ud_min > 1:
			ud_min = 1
		if ud_min == 0 and lr_min > 1:
			lr_min = 1
		c['L'] = lr_min
		c['R'] = lr_min
		c['U'] = ud_min
		c['D'] = ud_min
		move = ''
		move += 'L' * lr_min
		move += 'U' * ud_min
		move += 'R' * lr_min
		move += 'D' * ud_min
		ans.append(move)
	for t in range(q):
		print(len(ans[t]))
		print(ans[t])

def __starting_point():
	main()
__starting_point()


for _ in range(int(input())):
	s = input()
	lr = min(s.count('L'), s.count('R'))
	ud = min(s.count('U'), s.count('D'))
	if ud == 0 and lr == 0:
		print(0)
		print()
	elif ud == 0 or lr == 0:
		if lr == 0:
			print(2)
			print('UD')
		else:
			print(2)
			print('LR')
	else:
		l = 2 * lr + 2 * ud
		s1 = 'L' * lr + 'U' * ud + 'R' * lr + 'D' * ud
		print(l)
		print(s1)


t = int(input())
for i in range(t):
	s = input()
	cl = 0
	cr = 0
	cu = 0
	cd = 0
	for j in range(len(s)):
		if s[j] == 'L':
			cl += 1
		elif s[j] == 'R':
			cr += 1
		elif s[j] == 'U':
			cu += 1
		else:
			cd += 1
	acr = min(cr, cl)
	dow = min(cu, cd)
	if acr == 0 and dow != 0:
		print(2)
		print('UD')
	elif dow == 0 and acr != 0:
		print(2)
		print('LR')
	elif dow == 0 and acr == 0:
		print(0)
	else:
		print(2 * (acr + dow))
		for j in range(acr):
			print('L', end='')
		for j in range(dow):
			print('U', end='')
		for j in range(acr):
			print('R', end='')
		for j in range(dow):
			print('D', end='')
		print()


t = int(input())
while t != 0:
	t -= 1
	s = input()
	a = [s.count('L'), s.count('R'), s.count('U'), s.count('D')]
	if a[0] == 0 or a[1] == 0 or a[2] == 0 or (a[3] == 0):
		if a[0] > 0 and a[1] > 0:
			print(2)
			print('LR')
		elif a[2] > 0 and a[3] > 0:
			print(2)
			print('UD')
		else:
			print(0)
			print('')
	else:
		p = min(a[0], a[1])
		q = min(a[2], a[3])
		print(2 * p + 2 * q)
		for i in range(p):
			print('L', end='')
		for i in range(q):
			print('U', end='')
		for i in range(p):
			print('R', end='')
		for i in range(q):
			print('D', end='')
		print()


for _ in '0' * int(input()):
	d = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for c in input():
		d[c] += 1
	(LR, UD) = (min(d['L'], d['R']), min(d['U'], d['D']))
	if UD == 0 and LR != 0:
		LR = 1
	elif LR == 0 and UD != 0:
		UD = 1
	print(LR * 2 + UD * 2)
	print('L' * LR + 'U' * UD + 'R' * LR + 'D' * UD)


for i in range(int(input())):
	s = input()
	left = s.count('L')
	right = s.count('R')
	up = s.count('U')
	down = s.count('D')
	left = min(left, right)
	right = left
	up = min(up, down)
	down = up
	if left == 0 and up == 0:
		pass
	elif up == 0:
		left = 1
		right = 1
	elif left == 0:
		up = 1
		down = 1
	print(left + right + up + down)
	print('L' * left + 'U' * up + 'R' * right + 'D' * down)


for _ in range(int(input())):
	L = list(input())
	countU = 0
	countD = 0
	countR = 0
	countL = 0
	for i in L:
		if i == 'L':
			countL += 1
		if i == 'R':
			countR += 1
		if i == 'D':
			countD += 1
		if i == 'U':
			countU += 1
	ans = 0
	X1 = min(countL, countR)
	X2 = min(countU, countD)
	FLAG = 0
	S = 'L' * X1 + 'U' * X2
	S = S + 'R' * X1 + 'D' * X2
	if X2 == 0 and X1 > 0:
		S = 'LR'
		FLAG = 1
	elif X2 > 0 and X1 == 0:
		S = 'UD'
		FLAG = 1
	if FLAG == 1:
		print(2)
	else:
		print(2 * (X1 + X2))
	print(S)


for _ in range(int(input())):
	s = input()
	(l, r, u, d) = (0, 0, 0, 0)
	for i in s:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	a = min(r, l)
	b = min(u, d)
	le = 2 * a + 2 * b
	if a == 0 or b == 0:
		print(min(le, 2))
		print('L' * min(a, 1) + 'U' * min(b, 1) + 'R' * min(a, 1) + 'D' * min(b, 1))
	else:
		print(le)
		print('L' * a + 'U' * b + 'R' * a + 'D' * b)


n = int(input())
for i in range(n):
	s = input()
	u = s.count('U')
	d = s.count('D')
	l = s.count('L')
	r = s.count('R')
	minud = min(u, d)
	minlr = min(r, l)
	if minud == 0 and minlr == 0:
		print(0)
		print()
	elif minud == 0:
		print(2)
		print('LR')
	elif minlr == 0:
		print(2)
		print('UD')
	else:
		print(minlr * 2 + minud * 2)
		print('L' * minlr + 'U' * minud + 'R' * minlr + 'D' * minud)


for i in range(int(input())):
	a = input()
	b = a.count('L')
	c = a.count('R')
	d = a.count('U')
	e = a.count('D')
	if b > c:
		b = c
	else:
		c = b
	if d > e:
		d = e
	else:
		e = d
	if b == 0 and e != 0:
		print(2)
		print('UD')
	elif e == 0 and b != 0:
		print(2)
		print('LR')
	else:
		r = ''
		t = ''
		for k in range(b):
			r += 'L'
			t += 'R'
		for j in range(e):
			r += 'U'
			t += 'D'
		r = r + t
		print(len(r))
		print(r)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	s = input()
	directions = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for i in s:
		directions[i] += 1
	l = directions['L']
	r = directions['R']
	u = directions['U']
	d = directions['D']
	(l, r) = (min(l, r), min(l, r))
	(u, d) = (min(u, d), min(u, d))
	res = ''
	res = 'L' * l + 'U' * u + 'R' * r + 'D' * d
	if u == d == 0 and l > 1 and (r > 1):
		res = 'LR'
	elif l == r == 0 and u > 1 and (d > 1):
		res = 'UD'
	print(len(res))
	print(res)
t = int(input())
for _ in range(t):
	main()


q = int(input())
for i in range(q):
	s = input()
	n = len(s)
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	x = min(l, r)
	y = min(u, d)
	if x == 0 and y == 0:
		pass
	elif x == 0:
		y = 1
	elif y == 0:
		x = 1
	z = 2 * x + 2 * y
	print(z)
	print('L' * x + 'U' * y + 'R' * x + 'D' * y)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
for _ in range(get_int()):
	s = get_string()
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	l_r = min(l, r)
	u_d = min(u, d)
	if l_r > 0 and u_d > 0:
		res = l_r * 'L' + u_d * 'U' + l_r * 'R' + u_d * 'D'
	elif l_r == 0 and u_d != 0:
		res = 'UD'
	elif l_r != 0 and u_d == 0:
		res = 'LR'
	else:
		res = ''
	if len(res) == 0:
		print(len(res))
	else:
		print(len(res))
		print(res)


import sys
t = int(sys.stdin.readline())
for t in range(t):
	d = [0, 0, 0, 0]
	s = list(sys.stdin.readline().strip())
	string = ''
	for i in s:
		if i == 'L':
			d[0] += 1
		elif i == 'R':
			d[1] += 1
		elif i == 'U':
			d[2] += 1
		elif i == 'D':
			d[3] += 1
	if d[0] > 0 and d[1] > 0 and (d[2] > 0) and (d[3] > 0):
		minVal1 = min(d[0:2])
		minVal2 = min(d[2:4])
		for i in range(0, 2):
			d[i] = minVal1
		for i in range(2, 4):
			d[i] = minVal2
		temp = d[1]
		d[1] = d[2]
		d[2] = temp
		for j in range(len(d)):
			if j == 0:
				string += 'L' * d[j]
			elif j == 1:
				string += 'U' * d[j]
			elif j == 2:
				string += 'R' * d[j]
			elif j == 3:
				string += 'D' * d[j]
		print(len(string))
		print(string)
	elif d[0] > 0 and d[1] > 0 and (d[2] == 0) and (d[3] == 0):
		print(2)
		print('LR')
	elif d[0] > 0 and d[1] > 0 and (d[2] > 0) and (d[3] == 0):
		print(2)
		print('LR')
	elif d[0] > 0 and d[1] > 0 and (d[2] == 0) and (d[3] > 0):
		print(2)
		print('LR')
	elif d[0] == 0 and d[1] == 0 and (d[2] > 0) and (d[3] > 0):
		print(2)
		print('UD')
	elif d[0] == 0 and d[1] > 0 and (d[2] > 0) and (d[3] > 0):
		print(2)
		print('UD')
	elif d[0] > 0 and d[1] == 0 and (d[2] > 0) and (d[3] > 0):
		print(2)
		print('UD')
	else:
		print(0)


Q = int(input())
for _ in range(Q):
	s = input()
	d = {0: 0, 1: 0, 2: 0, 3: 0}
	for i in s:
		if i == 'L':
			d[0] += 1
		elif i == 'U':
			d[1] += 1
		elif i == 'R':
			d[2] += 1
		else:
			d[3] += 1
	if d[0] == 0 or d[1] == 0 or d[2] == 0 or (d[3] == 0):
		if min(d[0], d[2]) == 0 and min(d[1], d[3]) == 0:
			print(0)
			continue
		print(2)
		if d[0] == 0 or d[2] == 0:
			print('UD')
		else:
			print('LR')
		continue
	d[0] = min(d[0], d[2])
	d[2] = d[0]
	d[1] = min(d[1], d[3])
	d[3] = d[1]
	print(d[0] + d[1] + d[2] + d[3])
	print('L' * d[0] + 'U' * d[1] + 'R' * d[2] + 'D' * d[3])


for _ in range(int(input())):
	s = input()
	(l, r, u, d) = (s.count(x) for x in 'LRUD')
	(x, y) = (min(l, r), min(u, d))
	if x and y:
		print((x + y) * 2)
		print('L' * x + 'U' * y + 'R' * x + 'D' * y)
	elif x:
		print(2)
		print('LR')
	elif y:
		print(2)
		print('UD')
	else:
		print(0)


import sys, math, itertools, heapq, collections, bisect, string
inf = float('inf')
mod = 10 ** 9 + 7
ans = inf
count = 0
pro = 1

def solve():
	S = input()
	C = collections.Counter(S)
	C['U'] = min(C['U'], C['D'])
	C['D'] = min(C['U'], C['D'])
	C['L'] = min(C['L'], C['R'])
	C['R'] = min(C['L'], C['R'])
	if C['U'] == 0:
		C['L'] = min(C['L'], 1)
		C['R'] = min(C['R'], 1)
	if C['L'] == 0:
		C['U'] = min(C['U'], 1)
		C['D'] = min(C['D'], 1)
	data = {'U': 1, 'D': 3, 'R': 2, 'L': 0}
	ans = [''] * 4
	for (k, w) in C.items():
		ans[data[k]] = k * w
	print(len(''.join(ans)))
	print(''.join(ans))
n = int(input())
for i in range(n):
	solve()


for _ in range(int(input())):
	s = input()
	right = s.count('R')
	left = s.count('L')
	up = s.count('U')
	down = s.count('D')
	lr = min(right, left)
	ud = min(up, down)
	if ud == 0 and lr != 0:
		lr = 1
	if lr == 0 and ud != 0:
		ud = 1
	ans = ''
	for i in range(lr):
		ans += 'L'
	for i in range(ud):
		ans += 'U'
	for i in range(lr):
		ans += 'R'
	for i in range(ud):
		ans += 'D'
	print(2 * (lr + ud))
	print(ans)


from collections import Counter

def main():
	for _ in range(int(input())):
		d = Counter(input())
		(lr, ud) = (min(d['L'], d['R']), min(d['U'], d['D']))
		lr = lr if ud else min(lr, 1)
		ud = ud if lr else min(ud, 1)
		print(f"{2 * (lr + ud)}\n{'L' * lr + 'U' * ud + 'R' * lr + 'D' * ud}")
main()


try:
	t = int(input())
	for i in range(t):
		t = list(input())
		d = t.count('D')
		u = t.count('U')
		l = t.count('L')
		r = t.count('R')
		if d >= u:
			d = u
		else:
			u = d
		if l >= r:
			l = r
		else:
			r = l
		if d == 0 and l == 0:
			print(0)
			print(' ')
		elif l == 0:
			print(2)
			print(l * 'L' + 'U' + r * 'R' + 'D')
		elif d == 0:
			print(2)
			print('L' + 'R')
		else:
			print(r + l + u + d)
			print(l * 'L' + u * 'U' + r * 'R' + d * 'D')
except Exception:
	pass


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		s = S()
		r = ''
		c = collections.Counter(s)
		if len(c) < 4:
			if c['L'] and c['R']:
				r = 'LR'
			elif c['U'] and c['D']:
				r = 'UD'
		else:
			t = min(c['L'], c['R'])
			u = min(c['U'], c['D'])
			r = 'L' * t + 'U' * u + 'R' * t + 'D' * u
		rr.append(len(r))
		rr.append(r)
	return JA(rr, '\n')
print(main())


def play(str):
	cSet = {}
	for c in str:
		cSet[c] = cSet.get(c, 0) + 1
	h = min(cSet.get('L', 0), cSet.get('R', 0))
	v = min(cSet.get('U', 0), cSet.get('D', 0))
	if h == 0:
		if v > 0:
			return 'UD'
		else:
			return ''
	elif v == 0:
		return 'LR'
	else:
		return 'L' * h + 'U' * v + 'R' * h + 'D' * v

def play2(str):
	r = play(str)
	print(len(r))
	print(r)

def main():
	n = list(map(int, input().split()))[0]
	while n > 0:
		str = input()
		play2(str)
		n -= 1
main()


q = int(input())
while q:
	s = input()
	l = 0
	r = 0
	u = 0
	d = 0
	for i in s:
		if i == 'L':
			l = l + 1
		if i == 'R':
			r = r + 1
		if i == 'U':
			u = u + 1
		if i == 'D':
			d = d + 1
	h = min(l, r)
	v = min(u, d)
	if h == 0 and v != 0:
		v = 1
	if v == 0 and h != 0:
		h = 1
	m = 2 * (h + v)
	print(m)
	if h == 1 and v != 1:
		print(h * 'L', end='')
		print(h * 'R')
	if v == 1 and h != 1:
		print('U', end='')
		print('D')
	if h != 1 and v != 1 or (h == 1 and v == 1):
		print(h * 'L', end='')
		print(v * 'U', end='')
		print(h * 'R', end='')
		print(v * 'D')
	q = q - 1


t = int(input())
while t > 0:
	a = input()
	l = len(a)
	(p, q, r, s) = (0, 0, 0, 0)
	for x in range(l):
		if a[x] == 'L':
			p += 1
		if a[x] == 'R':
			q += 1
		if a[x] == 'U':
			r += 1
		if a[x] == 'D':
			s += 1
	p = min(p, q)
	r = min(r, s)
	if p == 0 and r == 0:
		print(p)
	elif p == 0:
		print('2')
		print('UD')
	elif r == 0:
		print('2')
		print('LR')
	else:
		print(2 * p + 2 * r)
		for i in range(p):
			print('L', end='')
		for i in range(r):
			print('U', end='')
		for i in range(p):
			print('R', end='')
		for i in range(r):
			print('D', end='')
		print()
	t -= 1


t = eval(input())
inputs = list()
for _ in range(t):
	temp = input()
	inputs.append(temp)
for walks in inputs:
	length = len(walks)
	walked = [0] * 4
	prev = ''
	for x in range(len(walks)):
		drxn = walks[x]
		if drxn == 'L':
			walked[0] += 1
		elif drxn == 'R':
			walked[1] += 1
		elif drxn == 'U':
			walked[2] += 1
		elif drxn == 'D':
			walked[3] += 1
	if walked[0] != walked[1]:
		diff = abs(walked[0] - walked[1])
		if walked[0] > walked[1]:
			walked[0] -= diff
		else:
			walked[1] -= diff
	if walked[2] != walked[3]:
		diff = abs(walked[2] - walked[3])
		if walked[2] > walked[3]:
			walked[2] -= diff
		else:
			walked[3] -= diff
	if walked[0] == walked[1] == 0 and walked[2] != 0 and (walked[3] != 0):
		walked[2] = 1
		walked[3] = 1
		length = 2
	elif walked[2] == walked[3] == 0 and walked[0] != 0 and (walked[1] != 0):
		walked[0] = 1
		walked[1] = 1
		length = 2
	res = 'L' * walked[0] + 'U' * walked[2] + 'R' * walked[1] + 'D' * walked[3]
	print(sum(walked))
	print(res)


T = int(input())
for i in range(T):
	S = input()
	lrdu = [0, 0, 0, 0]
	for x in S:
		if x == 'L':
			lrdu[0] += 1
		if x == 'R':
			lrdu[1] += 1
		if x == 'D':
			lrdu[2] += 1
		if x == 'U':
			lrdu[3] += 1
	ml = min(lrdu[0], lrdu[1])
	dl = max(lrdu[0], lrdu[1]) - ml
	mu = min(lrdu[2], lrdu[3])
	du = max(lrdu[2], lrdu[3]) - mu
	if ml == 0 or mu == 0:
		if ml == 0 and mu == 0:
			print(0)
			print('')
		if ml != 0:
			print(2)
			print('LR')
		if mu != 0:
			print(2)
			print('UD')
	else:
		moves = len(S) - dl - du
		So = ''
		for j in range(ml):
			So += 'L'
		for j in range(mu):
			So += 'U'
		for j in range(ml):
			So += 'R'
		for j in range(mu):
			So += 'D'
		print(moves)
		print(So)


q = int(input())
while q:
	b = list(map(str, input()))
	ud = 0
	uu = 0
	ul = 0
	ur = 0
	s = ''
	for i in b:
		if i == 'U':
			uu = uu + 1
		elif i == 'L':
			ul = ul + 1
		elif i == 'D':
			ud = ud + 1
		elif i == 'R':
			ur = ur + 1
	u_d = min(uu, ud)
	u_l = min(ul, ur)
	if u_l == u_d == 0:
		print(0)
	elif u_l == 0:
		u_d = 1
		s = 'L' * u_l + 'U' * u_d + 'R' * u_l + 'D' * u_d
		print(len(s))
		print(s)
	elif u_d == 0:
		u_l = 1
		s = 'L' * u_l + 'U' * u_d + 'R' * u_l + 'D' * u_d
		print(len(s))
		print(s)
	else:
		s = 'L' * u_l + 'U' * u_d + 'R' * u_l + 'D' * u_d
		print(len(s))
		print(s)
	q = q - 1


q = int(input())
for i in range(q):
	s = list(input())
	(l, r, u, d) = (0, 0, 0, 0)
	for i in s:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	(a, b) = (min(l, r), min(u, d))
	if a == 0 and b == 0:
		print('0')
	elif a == 0:
		print('2')
		print('UD')
	elif b == 0:
		print('2')
		print('LR')
	else:
		print(2 * a + 2 * b)
		print(a * 'L' + b * 'U' + a * 'R' + b * 'D')


def read():
	return input()

def solve(s):
	left = right = up = down = 0
	for si in s:
		if si == 'L':
			left += 1
		elif si == 'R':
			right += 1
		elif si == 'U':
			up += 1
		else:
			down += 1
	h = min(left, right)
	v = min(down, up)
	if h == 0:
		return '' if v == 0 else 'UD'
	if v == 0:
		return '' if h == 0 else 'LR'
	return 'L' * h + 'U' * v + 'R' * h + 'D' * v
for t in range(int(input())):
	result = solve(read())
	print(len(result))
	if len(result):
		print(result)


from collections import deque, Counter
import array
from itertools import combinations, permutations
from math import sqrt
import unittest

def read_int():
	return int(input().strip())

def read_int_array():
	return [int(i) for i in input().strip().split(' ')]
for test in range(read_int()):
	s = input().strip()
	l = 0
	r = 0
	u = 0
	d = 0
	for c in s:
		if c == 'L':
			l += 1
		elif c == 'R':
			r += 1
		elif c == 'D':
			d += 1
		elif c == 'U':
			u += 1
	du = min(d, u)
	lr = min(l, r)
	if du == 0:
		lr = min(lr, 1)
	if lr == 0:
		du = min(du, 1)
	print(lr * 2 + du * 2)
	print('L' * lr + 'U' * du + 'R' * lr + 'D' * du)


from collections import defaultdict
import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	s = list(input().rstrip())
	cnt = defaultdict(lambda : 0)
	for i in s:
		cnt[i] += 1
	lr = min(cnt['L'], cnt['R'])
	ud = min(cnt['U'], cnt['D'])
	if not lr and ud:
		ud = 1
	if not ud and lr:
		lr = 1
	ans = 2 * (lr + ud)
	print(ans)
	ans = 'L' * lr + 'U' * ud + 'R' * lr + 'D' * ud
	print(ans)


from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
t = ii()
for i in range(t):
	a = input()
	l = a.count('L')
	r = a.count('R')
	u = a.count('U')
	d = a.count('D')
	x = min(l, r)
	y = min(u, d)
	if x == 0 and y == 0:
		print(0)
	elif x == 0 and y > 0 or (y == 0 and x > 0):
		print(2)
		if x == 0:
			print('UD')
		else:
			print('LR')
	else:
		s = 'L' * x + 'U' * y + 'R' * x + 'D' * y
		print(len(s))
		print(s)


import sys
input = sys.stdin.readline
Q = int(input())
Ss = [list(input().rstrip()) for _ in range(Q)]
for S in Ss:
	dic = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for s in S:
		dic[s] += 1
	LR = min(dic['L'], dic['R'])
	UD = min(dic['U'], dic['D'])
	if LR == 0:
		print(min(UD, 1) * 2)
		print('UD' * min(UD, 1))
	elif UD == 0:
		print(min(LR, 1) * 2)
		print('LR' * min(LR, 1))
	else:
		print((LR + UD) * 2)
		print('L' * LR + 'U' * UD + 'R' * LR + 'D' * UD)


for _ in range(int(input())):
	s = input()
	(l, u, r, d) = (s.count('L'), s.count('U'), s.count('R'), s.count('D'))
	h = min(l, r)
	v = min(u, d)
	if h == 0:
		v = 1 if v > 0 else 0
	if v == 0:
		h = 1 if h > 0 else 0
	print(2 * (h + v))
	print('L' * h + 'U' * v + 'R' * h + 'D' * v)


def strng(n, s):
	return n * s
for _ in range(int(input())):
	s = list(input())
	cl = cr = cu = cd = 0
	for i in range(len(s)):
		if s[i] == 'L':
			cl += 1
		if s[i] == 'R':
			cr += 1
		if s[i] == 'U':
			cu += 1
		if s[i] == 'D':
			cd += 1
	v = min(cu, cd)
	h = min(cl, cr)
	if min(v, h) == 0:
		if v == 0:
			h = min(h, 1)
			print(2 * h)
			print(strng(h, 'L') + strng(h, 'R'))
		else:
			v = min(v, 1)
			print(2 * v)
			print(strng(v, 'U') + strng(v, 'D'))
	else:
		res = ''
		res += strng(h, 'L')
		res += strng(v, 'U')
		res += strng(h, 'R')
		res += strng(v, 'D')
		print(len(res))
		print(res)


for _ in range(int(input())):
	s = input()
	l_count = s.count('L')
	r_count = s.count('R')
	u_count = s.count('U')
	d_count = s.count('D')
	horiz_count = min(l_count, r_count)
	vert_count = min(u_count, d_count)
	ans = ''
	if vert_count == 0:
		if horiz_count >= 1:
			ans += 'LR'
	elif horiz_count == 0:
		ans += 'UD'
	else:
		ans = 'L' * horiz_count + 'U' * vert_count + 'R' * horiz_count + 'D' * vert_count
	print(len(ans))
	print(ans)


from collections import defaultdict
q = int(input())
for _ in range(q):
	s = input()
	data = [0, 0, 0, 0]
	for i in s:
		if i == 'L':
			data[0] += 1
		if i == 'R':
			data[1] += 1
		if i == 'U':
			data[2] += 1
		if i == 'D':
			data[3] += 1
	if min(data[0], data[1]) == 0 and min(data[2], data[3]) == 0:
		print(0)
		continue
	elif min(data[0], data[1]) == 0:
		print(2)
		print('UD')
		continue
	elif min(data[2], data[3]) == 0:
		print(2)
		print('LR')
		continue
	ans = (min(data[0], data[1]) + min(data[2], data[3])) * 2
	q = 'L' * min(data[0], data[1]) + 'U' * min(data[2], data[3])
	q += 'R' * min(data[0], data[1]) + 'D' * min(data[2], data[3])
	print(ans)
	print(q)


def snow(s):
	(left, right, up, down) = (s.count('L'), s.count('R'), s.count('U'), s.count('D'))
	(m1, m2) = (min(left, right), min(up, down))
	if m2 == 0 and m1 > 0:
		return (2, 'LR')
	elif m2 > 0 and m1 == 0:
		return (2, 'UD')
	return (2 * (m1 + m2), 'L' * m1 + 'U' * m2 + 'R' * m1 + 'D' * m2)
for _ in range(int(input())):
	t = input()
	print(*list(snow(t)), sep='\n')


for _ in range(int(input())):
	s = input()
	(l, r, u, d) = (0, 0, 0, 0)
	for i in s:
		l = l + (i == 'L')
		r = r + (i == 'R')
		u = u + (i == 'U')
		d = d + (i == 'D')
	if min(l, r) and min(u, d):
		out = 'L' * min(l, r) + 'U' * min(u, d) + 'R' * min(l, r) + 'D' * min(u, d)
	elif min(l, r):
		out = 'LR'
	elif min(u, d):
		out = 'UD'
	else:
		out = ''
	print(len(out))
	print(out)


for T in range(int(input())):
	ans = 0
	ansStr = ''
	arr = input()
	mp = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for ch in arr:
		mp[ch] += 1
	lr = min(mp['L'], mp['R'])
	ud = min(mp['U'], mp['D'])
	if ud == 0:
		if lr == 0:
			print(0)
			print()
		else:
			print(2)
			print('LR')
	elif lr == 0:
		if ud == 0:
			print(0)
			print()
		else:
			print(2)
			print('UD')
	else:
		ans += (lr + ud) * 2
		for i in range(lr):
			ansStr += 'L'
		for i in range(ud):
			ansStr += 'U'
		for i in range(lr):
			ansStr += 'R'
		for i in range(ud):
			ansStr += 'D'
		print(ans)
		print(ansStr)


from collections import Counter
for q in range(int(input())):
	ins = Counter(input())
	lr = min(ins['L'], ins['R'])
	ud = min(ins['U'], ins['D'])
	if lr == ud == 0:
		print('0\n')
	elif lr == 0:
		print('2\nUD')
	elif ud == 0:
		print('2\nLR')
	else:
		print(lr + ud << 1)
		print('L' * lr + 'U' * ud + 'R' * lr + 'D' * ud)


q = int(input())
for _ in range(q):
	s = input()
	L = s.count('L')
	U = s.count('U')
	D = s.count('D')
	R = s.count('R')
	U = D = min(U, D)
	R = L = min(L, R)
	if U == 0:
		L = R = min(R, 1)
	if R == 0:
		U = D = min(U, 1)
	print(L + U + R + D)
	for _ in range(L):
		print('L', end='')
	for _ in range(U):
		print('U', end='')
	for _ in range(R):
		print('R', end='')
	for _ in range(D):
		print('D', end='')
	print()


q = int(input())
for testcase in range(q):
	s = input()
	Lcounter = 0
	Rcounter = 0
	Ucounter = 0
	Dcounter = 0
	for letter in s:
		if letter == 'L':
			Lcounter += 1
		if letter == 'R':
			Rcounter += 1
		if letter == 'U':
			Ucounter += 1
		if letter == 'D':
			Dcounter += 1
	LandRs = min(Lcounter, Rcounter)
	DandUs = min(Dcounter, Ucounter)
	if LandRs == 0:
		t = min(1, DandUs)
		print(2 * t)
		print('UD' * t)
	elif DandUs == 0:
		t = min(1, LandRs)
		print(2 * t)
		print('LR' * t)
	else:
		print(LandRs * 2 + DandUs * 2)
		print('L' * LandRs + 'U' * DandUs + 'R' * LandRs + 'D' * DandUs)


q = input()
ans_list = []
for _ in range(int(q)):
	seq = input()
	LR = [0, 0]
	UD = [0, 0]
	for idx in range(len(seq)):
		if seq[idx] == 'L':
			LR[0] += 1
		if seq[idx] == 'R':
			LR[1] += 1
		if seq[idx] == 'U':
			UD[0] += 1
		if seq[idx] == 'D':
			UD[1] += 1
	ans = ''
	LR_step = min(LR[0], LR[1])
	UD_step = min(UD[0], UD[1])
	if LR_step == 0 and UD_step != 0:
		ans = 'UD'
	elif UD_step == 0 and LR_step != 0:
		ans = 'LR'
	elif UD_step == 0 and LR_step == 0:
		ans = ''
	else:
		for _ in range(LR_step):
			ans += 'L'
		for _ in range(UD_step):
			ans += 'U'
		for _ in range(LR_step):
			ans += 'R'
		for _ in range(UD_step):
			ans += 'D'
	ans_list.append(ans)
for ans in ans_list:
	print(len(ans))
	print(ans)


n = int(input())
for i in range(n):
	s = input()
	loc = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for i in s:
		loc[i] = loc[i] + 1
	minlr = min(loc['L'], loc['R'])
	minud = min(loc['U'], loc['D'])
	res = 'L' * minlr
	res += 'U' * minud
	res += 'R' * minlr
	res += 'D' * minud
	if minlr == 0 and minud != 0:
		res = 'UD'
	elif minlr != 0 and minud == 0:
		res = 'LR'
	print(len(res))
	print(res)


from collections import Counter
test = int(input())
for _ in range(test):
	s = input()
	c = Counter(s)
	vertical = min(c['U'], c['D'])
	horizontal = min(c['L'], c['R'])
	if vertical == 0 and horizontal == 0:
		print(0)
	elif horizontal == 0:
		print(2)
		print('UD')
	elif vertical == 0:
		print(2)
		print('LR')
	else:
		print(2 * (vertical + horizontal))
		print('L' * horizontal + 'U' * vertical + 'R' * horizontal + 'D' * vertical)


for _ in range(int(input())):
	s = input().strip()
	(l, r, u, d) = (s.count('L'), s.count('R'), s.count('U'), s.count('D'))
	l = min(l, r)
	u = min(u, d)
	if l == 0:
		u = min(u, 1)
	elif u == 0:
		l = min(l, 1)
	ans = 2 * l + 2 * u
	s = 'L' * l + 'U' * u + 'R' * l + 'D' * u
	print(ans)
	print(s)


q = int(input())
while q:
	s = input()
	m = {}
	m['D'] = 0
	m['U'] = 0
	m['L'] = 0
	m['R'] = 0
	for i in s:
		m[i] += 1
	k = min(m['D'], m['U'])
	m['D'] = k
	m['U'] = k
	k1 = min(m['L'], m['R'])
	m['L'] = k1
	m['R'] = k1
	if m['D'] == 0:
		m['L'] = min(1, m['L'])
		m['R'] = m['L']
	if m['L'] == 0:
		m['D'] = min(m['D'], 1)
		m['U'] = m['D']
	print(m['L'] + m['D'] + m['R'] + m['U'])
	print('L' * m['L'], end='')
	print('U' * m['U'], end='')
	print('R' * m['R'], end='')
	print('D' * m['D'])
	q -= 1


t = int(input())
ans1 = []
ans2 = []
for i in range(0, t):
	s = input()
	new = ''
	letter = len(s)
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	if abs(l - r) != 0 and abs(u - d) != 0:
		if l > r:
			l = l - abs(l - r)
		else:
			r = r - abs(l - r)
		if u > d:
			u = u - abs(u - d)
		else:
			d = d - abs(u - d)
		new = new + 'L' * l + 'R' * r + 'U' * u + 'D' * d
	elif abs(l - r) != 0:
		if l > r:
			l = l - abs(l - r)
			new = new + 'L' * l + 'R' * r + 'U' * u + 'D' * d
		else:
			r = r - abs(l - r)
			new = new + 'L' * l + 'R' * r + 'U' * u + 'D' * d
	elif abs(u - d) != 0:
		if u > d:
			u = u - abs(u - d)
			new = new + 'L' * l + 'R' * r + 'U' * u + 'D' * d
		else:
			d = d - abs(u - d)
			new = new + 'L' * l + 'R' * r + 'U' * u + 'D' * d
	letter = l + u + d + r
	if l == 0 and u == 0:
		letter = 0
		ans1.append(letter)
		ans2.append('')
	elif l == 0:
		letter = 2
		ans1.append(letter)
		ans2.append('UD')
	elif u == 0:
		letter = 2
		ans1.append(letter)
		ans2.append('LR')
	elif new != '':
		ans1.append(letter)
		l = new.count('L')
		r = new.count('R')
		u = new.count('U')
		d = new.count('D')
		final = ''
		final = 'L' * l + 'U' * u + 'R' * r + 'D' * d
		ans2.append(final)
	else:
		ans1.append(letter)
		final = ''
		final = 'L' * l + 'U' * u + 'R' * r + 'D' * d
		ans2.append(final)
for k in range(0, t):
	print(ans1[k])
	print(ans2[k])


t = int(input())
for i in range(0, t):
	s = input()
	s1 = s.count('L')
	s2 = s.count('R')
	s3 = s.count('U')
	s4 = s.count('D')
	flag1 = 1
	flag2 = 1
	if s1 == 0 or s2 == 0 or s3 == 0 or (s4 == 0):
		if s4 > 0 and s3 > 0:
			print(2)
			print('UD')
		elif s2 > 0 and s1 > 0:
			print(2)
			print('LR')
		else:
			print(0)
			print('')
	else:
		print(len(s) - abs(s1 - s2) - abs(s3 - s4))
		x1 = min(s1, s2)
		x2 = min(s3, s4)
		for j in range(0, x1):
			print('L', sep='', end='')
		for j in range(0, x2):
			print('U', sep='', end='')
		for j in range(0, x1):
			print('R', sep='', end='')
		for j in range(0, x2):
			print('D', sep='', end='')
		print('')


from sys import stdin, stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	s = is1()
	d = Counter(s)
	(l, r) = (d['L'], d['R'])
	(u, d) = (d['U'], d['D'])
	x = min(l, r)
	y = min(u, d)
	if x == 0 and y == 0:
		print(0)
	elif y > 1 and x == 0:
		print(2)
		print('UD')
	elif x > 1 and y == 0:
		print(2)
		print('LR')
	else:
		s = 'L' * x + 'U' * y + 'R' * x + 'D' * y
		print(len(s))
		print(s)


def __equalize__(moves):
	a = moves['L']
	b = moves['R']
	c = moves['U']
	d = moves['D']
	moves['L'] = moves['R'] = min(a, b)
	moves['U'] = moves['D'] = min(c, d)
	if moves['U'] == 0 and moves['L'] > 1:
		moves['L'] = moves['R'] = 1
	if moves['R'] == 0 and moves['U'] > 1:
		moves['U'] = moves['D'] = 1

def __move__(start, move):
	if move == 'L':
		return (start[0] - 1, start[1])
	elif move == 'R':
		return (start[0] + 1, start[1])
	elif move == 'U':
		return (start[0], start[1] + 1)
	elif move == 'D':
		return (start[0], start[1] - 1)

def correct(path):
	moves = {'L': 0, 'U': 0, 'R': 0, 'D': 0}
	current = (0, 0)
	results = []
	for i in path:
		moves[i] += 1
	__equalize__(moves)
	moves_count = moves['L'] + moves['U'] + moves['R'] + moves['D']
	if moves_count > 0:
		for i in moves:
			for j in range(moves[i]):
				r = __move__(current, i)
				current = r
				results.append(i)
				moves[i] -= 1
	result = ''.join(results)
	return (str(moves_count), result)

def solution(inp):
	return correct(inp)

def main():
	inp1 = input()
	length = int(inp1)
	result = []
	for i in range(length):
		s = solution(input())
		result.append(s[0])
		if int(s[0]) > 0:
			result.append(s[1])
	print(*result, sep='\n', end='')
main()


t = int(input())
for ii in range(t):
	s = input()
	x = min(s.count('L'), s.count('R'))
	y = min(s.count('U'), s.count('D'))
	xz = max(s.count('L'), s.count('R'))
	yz = max(s.count('U'), s.count('D'))
	if xz == len(s) or yz == len(s):
		print(0)
		print()
	else:
		if x == 0:
			y = min(1, y)
		elif y == 0:
			x = min(1, x)
		xx = x * 'L' + y * 'U' + x * 'R' + y * 'D'
		print(len(xx))
		print(xx)


import sys
q = int(sys.stdin.readline())
for _ in range(q):
	s = sys.stdin.readline().strip()
	left = s.count('L')
	right = s.count('R')
	up = s.count('U')
	down = s.count('D')
	lr = min(left, right)
	ud = min(up, down)
	if ud == 0 and lr > 0:
		print('2')
		print('LR')
	elif ud > 0 and lr == 0:
		print('2')
		print('UD')
	else:
		print(2 * (lr + ud))
		print('L' * lr + 'U' * ud + 'R' * lr + 'D' * ud)


from sys import exit

def iis():
	return map(int, input().split())

def ii():
	return int(input())

def liis():
	return list(map(int, input().split()))

def get(s):
	u = s.count('U')
	d = s.count('D')
	l = s.count('L')
	r = s.count('R')
	ans = ''
	if min(l, r) >= 1:
		ans = 'LR'
	if min(u, d) >= 1:
		ans = 'UD'
	if min(u, d) >= 1 and min(l, r) >= 1:
		minx = min(l, r)
		miny = min(u, d)
		ans = minx * 'L' + miny * 'U' + minx * 'R' + miny * 'D'
	return ans
t = ii()
for _ in range(t):
	s = input()
	ans = get(s)
	print(len(ans))
	print(ans)
exit(0)


for _ in range(int(input())):
	s = input()
	m = [0] * 4
	m[0] = s.count('L')
	m[1] = s.count('U')
	m[2] = s.count('R')
	m[3] = s.count('D')
	if m[0] == 0 or m[2] == 0:
		m[0] = m[2] = 0
	if m[1] == 0 or m[3] == 0:
		m[1] = m[3] = 0
	if m[0] == 0 and m[1] > 0:
		m[1] = m[3] = 1
	if m[1] == 0 and m[0] > 0:
		m[0] = m[2] = 1
	if m[0] != m[2]:
		m[0] = m[2] = min(m[0], m[2])
	if m[1] != m[3]:
		m[1] = m[3] = min(m[1], m[3])
	print(sum(m))
	print('L' * m[0] + 'U' * m[1] + 'R' * m[2] + 'D' * m[3])


x = int(input())
for i in range(x):
	all_str = input()
	char_count = [0, 0, 0, 0]
	for c in all_str:
		if c == 'L':
			char_count[0] += 1
		if c == 'R':
			char_count[1] += 1
		if c == 'U':
			char_count[2] += 1
		if c == 'D':
			char_count[3] += 1
	min_LR = min(char_count[0], char_count[1])
	min_UD = min(char_count[2], char_count[3])
	if min_LR == 0:
		min_UD = min(1, min_UD)
	if min_UD == 0:
		min_LR = min(1, min_LR)
	print(2 * (min_LR + min_UD))
	print('L' * min_LR + 'U' * min_UD + 'R' * min_LR + 'D' * min_UD)


q = int(input())
for i in range(q):
	s = str(input())
	(l, r, u, d) = (0, 0, 0, 0)
	for t in s:
		if t == 'L':
			l += 1
		elif t == 'U':
			u += 1
		elif t == 'D':
			d += 1
		else:
			r += 1
	k = min(l, r)
	d = min(u, d)
	if d == 0:
		if k != 0:
			print(2)
			print('LR')
		else:
			print(0)
	elif k == 0:
		if d != 0:
			print(2)
			print('UD')
		else:
			print(0)
	else:
		print(k * 2 + d * 2)
		print('L' * k + 'U' * d + 'R' * k + 'D' * d)


order = {'L': 0, 'U': 1, 'R': 2, 'D': 3}

def fn(a):
	return order[a]
for _ in range(int(input())):
	s = list(input())
	n = len(s)
	s.sort(key=fn)
	mn2 = min(s.count('L'), s.count('R'))
	mn1 = min(s.count('U'), s.count('D'))
	mn = min(mn2, mn1)
	if mn == 0:
		if mn2 >= 1:
			print(2)
			print('LR')
		elif mn1 >= 1:
			print(2)
			print('UD')
		else:
			print(0)
			print('\n')
		continue
	s = 'L' * mn2 + 'U' * mn1 + 'R' * mn2 + 'D' * mn1
	print(len(s))
	print(s)


q = int(input())
for i in range(0, q):
	s = str(input())
	m = {c: 0 for c in ['L', 'U', 'D', 'R']}
	for c in s:
		m[c] += 1
	a = min(m['L'], m['R'])
	b = min(m['U'], m['D'])
	if a == 0 and b == 0:
		print('0')
		print('')
	elif a == 0 or b == 0:
		if a == 0:
			print(str(2 * min(b, 1)))
			print('UD')
		else:
			print(str(2 * min(a, 1)))
			print('LR')
	else:
		s = 2 * (a + b)
		print(str(s))
		ans = str()
		for i in range(0, a):
			ans += 'L'
		for i in range(0, b):
			ans += 'U'
		for i in range(0, a):
			ans += 'R'
		for i in range(0, b):
			ans += 'D'
		print(ans)


from collections import Counter
for _ in range(int(input())):
	s = Counter(list(input()))
	for e in ['L', 'R', 'U', 'D']:
		if e not in s.keys():
			s[e] = 0
	(mh, mv) = (min(s['L'], s['R']), min(s['U'], s['D']))
	if mv == 0 and mh != 0:
		mh = 1
	if mh == 0 and mv != 0:
		mv = 1
	print(mh * 2 + mv * 2)
	if mh + mv != 0:
		res = ''
		for k in ['L', 'U', 'R', 'D']:
			st = k * (mh if k == 'R' or k == 'L' else mv)
			res += st
		print(res)


q = int(input())
while q > 0:
	s = input()
	ans = 0
	sans = ''
	(l, r, u, d) = (0, 0, 0, 0)
	for x in s:
		if x == 'L':
			l += 1
		elif x == 'R':
			r += 1
		elif x == 'U':
			u += 1
		elif x == 'D':
			d += 1
	if l == 0 or r == 0:
		if u > 0 and d > 0:
			ans = 2
			sans = 'UD'
	elif u == 0 or d == 0:
		ans = 2
		sans = 'LR'
	else:
		lr = min(l, r)
		ud = min(u, d)
		sans = 'L' * lr + 'U' * ud + 'R' * lr + 'D' * ud
		ans = len(sans)
	print(ans)
	print(sans)
	q -= 1


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	s = stdin.readline().strip()
	counts = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for c in s:
		counts[c] += 1
	counts['L'] = counts['R'] = min(counts['L'], counts['R'])
	counts['U'] = counts['D'] = min(counts['D'], counts['U'])
	if counts['L'] == 0 and counts['U'] > 0:
		counts['U'] = counts['D'] = 1
	elif counts['U'] == 0 and counts['L'] > 0:
		counts['L'] = counts['R'] = 1
	stdout.write('{}\n'.format(sum(counts.values())))
	inst = ''
	inst += counts['L'] * 'L'
	inst += counts['U'] * 'U'
	inst += counts['R'] * 'R'
	inst += counts['D'] * 'D'
	stdout.write(inst + '\n')


from collections import Counter
for _ in range(int(input())):
	c = Counter(input())
	dx = min(c['L'], c['R'])
	dy = min(c['U'], c['D'])
	if dx < 1:
		dy = min(dy, 1)
	if dy < 1:
		dx = min(dx, 1)
	print(2 * (dx + dy))
	print('L' * dx + 'U' * dy + 'R' * dx + 'D' * dy)


import collections
for _ in range(int(input())):
	n = input()
	c = collections.Counter(n)
	L = min(c['L'], c['R'])
	U = min(c['U'], c['D'])
	if L == 0 and U == 0:
		print(0)
	elif L == 0 or U == 0:
		print(2)
		L = min(L, 1)
		U = min(U, 1)
		ans = 'L' * L + 'U' * U + 'R' * L + 'D' * U
		print(ans)
	elif L != 0 and U != 0:
		print(L * 2 + U * 2)
		ans = 'L' * L + 'U' * U + 'R' * L + 'D' * U
		print(ans)


q = int(input())
for i in range(q):
	s = input()
	(LEFT, UP, RIGHT, DOWN) = (0, 0, 0, 0)
	orig_length = len(s)
	for char in s:
		if char == 'L':
			LEFT += 1
		elif char == 'U':
			UP += 1
		elif char == 'R':
			RIGHT += 1
		elif char == 'D':
			DOWN += 1
	if LEFT != RIGHT:
		(LEFT, RIGHT) = (min(LEFT, RIGHT), min(LEFT, RIGHT))
	if UP != DOWN:
		(UP, DOWN) = (min(UP, DOWN), min(UP, DOWN))
	if LEFT == RIGHT == 0 and UP == DOWN != 0:
		(UP, DOWN) = (1, 1)
	if UP == DOWN == 0 and LEFT == RIGHT != 0:
		(LEFT, RIGHT) = (1, 1)
	print(LEFT + UP + RIGHT + DOWN)
	print('L' * LEFT + 'U' * UP + 'R' * RIGHT + 'D' * DOWN)


from collections import Counter

def main():
	S = input()
	c = Counter(S)
	LR = min(c['L'], c['R'])
	UD = min(c['U'], c['D'])
	if LR == 0 and UD == 0:
		ans = ''
	elif LR == 0:
		ans = 'UD'
	elif UD == 0:
		ans = 'LR'
	else:
		ans = 'L' * LR + 'U' * UD + 'R' * LR + 'D' * UD
	print(len(ans))
	print(ans)
q = int(input())
for i in range(q):
	main()


for _ in range(int(input())):
	s = list(input())
	sll = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for x in s:
		sll[x] = sll.get(x, 0) + 1
	sl = list(sll.items())
	lr = ud = 10 ** 9
	for x in sl:
		if x[0] in 'LR':
			lr = min(lr, x[1])
		else:
			ud = min(ud, x[1])
	if lr != 0 and ud != 0:
		print((lr + ud) * 2)
		print(lr * 'L' + ud * 'U' + lr * 'R' + ud * 'D')
	elif lr == 0 and ud != 0 or (lr != 0 and ud == 0):
		print(2)
		if ud != 0:
			print('UD')
		else:
			print('LR')
	else:
		print(0)
		print()


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		s = si()
		l = s.count('L')
		r = s.count('R')
		u = s.count('U')
		d = s.count('D')
		ans = ''
		ans += 'L' * min(l, r) + 'U' * min(u, d) + 'R' * min(l, r) + 'D' * min(u, d)
		if min(l, r) == 0:
			ans = ''
			ans = min(1, u, d) * 'UD'
		elif min(d, u) == 0:
			ans = ''
			ans = min(1, l, r) * 'LR'
		print(len(ans))
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


q = int(input())
for i in range(q):
	r = 0
	l = 0
	u = 0
	d = 0
	s = input()
	for c in s:
		if c == 'U':
			u += 1
		elif c == 'D':
			d += 1
		elif c == 'L':
			l += 1
		else:
			r += 1
	hor = min(l, r)
	vert = min(u, d)
	if hor == 0 and vert > 1:
		vert = 1
	elif vert == 0 and hor > 1:
		hor = 1
	if hor + vert == 0:
		print(0)
	else:
		ans = ''
		for i in range(hor):
			ans += 'L'
		for i in range(vert):
			ans += 'U'
		for i in range(hor):
			ans += 'R'
		for i in range(vert):
			ans += 'D'
		print(2 * (hor + vert))
		print(ans)


for _ in range(int(input())):
	string = input()
	left_count = down_count = right_count = up_count = 0
	for letter in string:
		if letter == 'U':
			up_count += 1
		elif letter == 'L':
			left_count += 1
		elif letter == 'D':
			down_count += 1
		else:
			right_count += 1
	min1 = min(right_count, left_count)
	min2 = min(up_count, down_count)
	if min1 == 0 and min2 != 0:
		print(2)
		print('UD')
	elif min2 == 0 and min1 != 0:
		print(2)
		print('LR')
	else:
		print(2 * min1 + 2 * min2)
		print('L' * min1 + 'U' * min2 + 'R' * min1 + 'D' * min2)


from os import path
import sys
from math import ceil, floor, gcd, log
from collections import defaultdict, Counter
maxx = float('inf')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	I = lambda : int(sys.stdin.buffer.readline())
	tup = lambda : map(int, sys.stdin.buffer.readline().split())
	lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
	S = lambda : sys.stdin.readline().replace('\n', '').strip()
	stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
	star = lambda x: print(' '.join(map(str, x)))
else:
	I = lambda : int(sys.stdin.buffer.readline())
	tup = lambda : map(int, sys.stdin.buffer.readline().split())
	lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
	S = lambda : sys.stdin.readline().replace('\n', '').strip()
	stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
	star = lambda x: print(' '.join(map(str, x)))
for _ in range(I()):
	(s, d) = (S(), {'R': 0, 'L': 0, 'U': 0, 'D': 0})
	for i in s:
		d[i] += 1
	(m1, m2) = (min(d['R'], d['L']), min(d['D'], d['U']))
	if m1 == 0:
		if m2 > 0:
			print(2, 'UD', sep='\n')
		else:
			print(0, '', sep='\n')
	elif m2 == 0:
		if m1 > 0:
			print(2, 'LR', sep='\n')
		else:
			print(0, '', sep='\n')
	else:
		print(m1 * 2 + m2 * 2)
		print('L' * m1 + 'U' * m2 + 'R' * m1 + 'D' * m2)


i = int(input())
for x in range(i):
	s = str(input())
	w = ''
	wl = 0
	u = 0
	d = 0
	l = 0
	r = 0
	for y in s:
		if y == 'U':
			u += 1
		if y == 'D':
			d += 1
		if y == 'R':
			r += 1
		if y == 'L':
			l += 1
	mlr = min(l, r)
	mud = min(u, d)
	if (u == 0 or d == 0) and l != 0 and (r != 0):
		print(2)
		print('LR')
		continue
	if (l == 0 or r == 0) and u != 0 and (d != 0):
		print(2)
		print('UD')
		continue
	for z in range(mlr):
		w += 'L'
		wl += 1
	for z in range(mud):
		w += 'U'
		wl += 1
	for z in range(mlr):
		w += 'R'
		wl += 1
	for z in range(mud):
		w += 'D'
		wl += 1
	print(wl)
	print(w)


lst = [0, 0, 0, 0]

def count(str1):
	global lst
	for i in str1:
		if i == 'L':
			lst[0] += 1
		elif i == 'R':
			lst[1] += 1
		elif i == 'U':
			lst[2] += 1
		elif i == 'D':
			lst[3] += 1

def assignmin():
	global lst
	if lst[0] < lst[1]:
		lst[1] = lst[0]
	elif lst[1] < lst[0]:
		lst[0] = lst[1]
	if lst[2] < lst[3]:
		lst[3] = lst[2]
	elif lst[3] < lst[2]:
		lst[2] = lst[3]
tc = int(input())
for k in range(tc):
	s1 = input()
	count(s1)
	res = ''
	assignmin()
	val = lst[0]
	val2 = lst[2]
	if lst[0] == 0 and lst[2] == 0:
		print('0')
		print()
	elif val == 0 and val2 != 0:
		print('2')
		print('UD')
	elif val2 == 0 and val != 0:
		print('2')
		print('LR')
	else:
		for i in range(val):
			res += 'L'
		for i in range(val2):
			res += 'U'
		for i in range(val):
			res += 'R'
		for i in range(val2):
			res += 'D'
		print(len(res))
		print(res)
	lst[0] = 0
	lst[1] = 0
	lst[2] = 0
	lst[3] = 0


from sys import stdin
infast = lambda : stdin.readline().strip()
Q = int(infast())
for _ in range(Q):
	S = infast()
	directions = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	for c in S:
		directions[c] += 1
	x = min(directions['L'], directions['R'])
	y = min(directions['U'], directions['D'])
	if x == 0 and y == 0:
		result = ''
	elif x == 0:
		result = 'UD'
	elif y == 0:
		result = 'LR'
	else:
		result = 'L' * x + 'U' * y + 'R' * x + 'D' * y
	print(len(result))
	print(result)


from collections import Counter
n = int(input())
for i in range(n):
	c = Counter(input())
	m = min(min(c['L'], c['U']), min(c['D'], c['R']))
	m2 = min(c['U'] - m, c['D'] - m)
	m1 = min(c['L'] - m, c['R'] - m)
	if m > 0:
		if m1 > 0:
			s = 'L' * (m + m1) + 'U' * m + 'R' * (m + m1) + 'D' * m
		elif m2 > 0:
			s = 'L' * m + 'U' * (m + m2) + 'R' * m + 'D' * (m + m2)
		else:
			s = 'L' * m + 'U' * m + 'R' * m + 'D' * m
	elif m1 > 0:
		s = 'LR'
	elif m2 > 0:
		s = 'UD'
	print(len(s))
	print(s)
	s = ''


import sys
from collections import Counter
for _ in range(int(input())):
	s = list(input())
	ans_length = len(s)
	dic = Counter(s)
	l_cnt = dic['L']
	u_cnt = dic['U']
	r_cnt = dic['R']
	d_cnt = dic['D']
	ud = min(u_cnt, d_cnt)
	lr = min(l_cnt, r_cnt)
	if lr == 0:
		if ud >= 1:
			print(2)
			print('UD')
		else:
			print(0)
	elif ud == 0:
		if lr >= 1:
			print(2)
			print('LR')
		else:
			print(0)
	else:
		print(2 * ud + 2 * lr)
		print('L' * lr + 'U' * ud + 'R' * lr + 'D' * ud)


for _ in range(int(input())):
	s = input()
	n = len(s)
	(l, r, u, d) = (s.count('L'), s.count('R'), s.count('U'), s.count('D'))
	if min(l, r) == 0 and max(l, r) != 0:
		l = r = 0
	if min(u, d) == 0 and max(u, d) != 0:
		u = d = 0
	hori = min(l, r)
	vert = min(u, d)
	if min(hori, vert) == 0 and max(hori, vert) > 1:
		hori = min(hori, 1)
		vert = min(vert, 1)
	res = 'L' * hori + 'U' * vert + 'R' * hori + 'D' * vert
	print(len(res))
	print(res)


from collections import Counter as cou
for _ in range(int(input())):
	s = input()
	c = cou(s)
	ds = c['D']
	us = c['U']
	ls = c['L']
	rs = c['R']
	if ds == 0 or us == 0:
		if ls != 0:
			ls = 1
	if rs == 0 or ls == 0:
		if ds != 0:
			ds = 1
	h = min(ls, rs)
	v = min(us, ds)
	print(2 * (h + v))
	for i in range(h):
		print('L', end='')
	for i in range(v):
		print('U', end='')
	for i in range(h):
		print('R', end='')
	for i in range(v):
		print('D', end='')
	print('')


def snowWalk(sample):
	howmany = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for i in range(0, len(sample)):
		howmany[sample[i]] += 1
	if howmany['L'] or howmany['R'] or howmany['U'] or (howmany['D'] != 0):
		if howmany['L'] > howmany['R']:
			howmany['L'] = howmany['R']
		else:
			howmany['R'] = howmany['L']
		if howmany['U'] > howmany['D']:
			howmany['U'] = howmany['D']
		else:
			howmany['D'] = howmany['U']
	if howmany['L'] and howmany['D'] != 0:
		distance = (howmany['D'] + howmany['R']) * 2
		print(distance)
		res = 'L' * howmany['L'] + 'U' * howmany['U'] + 'R' * howmany['R'] + 'D' * howmany['D']
		print(res)
	elif howmany['L'] == 0:
		if howmany['U'] != 0:
			print(2)
			print('UD')
		else:
			print(0)
	elif howmany['U'] == 0:
		if howmany['L'] != 0:
			print(2)
			print('LR')
		else:
			print(0)
	else:
		print(0)
number = eval(input())
if number > 0:
	for i in range(0, number):
		sample = input()
		snowWalk(sample)


from sys import stdin
from math import gcd
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	n = inp()
	d = {'L': 0, 'U': 0, 'R': 0, 'D': 0}
	for i in n:
		d[i] += 1
	if d['L'] > d['R']:
		d['L'] = d['R']
	else:
		d['R'] = d['L']
	if d['U'] > d['D']:
		d['U'] = d['D']
	else:
		d['D'] = d['U']
	if d['U'] == 0 and d['L']:
		d['L'] = 1
		d['R'] = 1
	if d['L'] == 0 and d['D']:
		d['U'] = 1
		d['D'] = 1
	ans = []
	for (i, j) in d.items():
		ans.extend([i] * j)
	print(len(ans))
	print(''.join(ans))


n = int(input())
for i in range(n):
	l = 0
	u = 0
	d = 0
	r = 0
	arr = []
	robo = input()
	for i in robo:
		if i == 'L':
			l += 1
		if i == 'R':
			r += 1
		if i == 'U':
			u += 1
		if i == 'D':
			d += 1
	l = r = min(r, l)
	u = d = min(u, d)
	if l == u == 0:
		print(0)
	elif l == 0:
		print(2)
		print('UD')
	elif u == 0:
		print(2)
		print('LR')
	else:
		for i in range(l):
			arr.append('L')
		for i in range(u):
			arr.append('U')
		for i in range(r):
			arr.append('R')
		for i in range(d):
			arr.append('D')
		print(2 * l + 2 * u)
		print(''.join((str(i) for i in arr)))


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict

def L():
	return list(map(int, stdin.readline().split()))

def Li():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	try:
		for _ in range(I()):
			(l, ans) = ([], [])
			l1 = list(input())
			(a, b, c, d) = (l1.count('R'), l1.count('L'), l1.count('U'), l1.count('D'))
			a = min(a, b)
			b = a
			c = min(c, d)
			d = c
			if c == 0 or d == 0:
				if a != 0 and b != 0:
					a = 1
					b = 1
			if a == 0 or b == 0:
				if c != 0 and d != 0:
					c = 1
					d = 1
			for i in range(b):
				ans.append('L')
			for i in range(c):
				ans.append('U')
			for i in range(a):
				ans.append('R')
			for i in range(d):
				ans.append('D')
			print(len(ans))
			print(''.join(ans))
	except:
		pass
main()


q = int(input())
for i in range(q):
	s = input()
	(l, r, u) = (s.count('L'), s.count('R'), s.count('U'))
	d = s.count('D')
	min1 = min([l, r])
	min2 = min([u, d])
	if min2 == 0 and min1 != 0:
		min1 = 1
	elif min1 == 0 and min2 != 0:
		min2 = 1
	res = 'L' * min1 + 'U' * min2 + 'R' * min1 + 'D' * min2
	print(len(res))
	print(res)


from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import math
for _ in range(int(input())):
	s = input()
	(l, r, u, d) = map(s.count, 'LRUD')
	x = min(l, r)
	y = min(u, d)
	if x == 0 and y == 0:
		print(0)
	elif x == 0:
		print(2)
		print('UD')
	elif y == 0:
		print(2)
		print('LR')
	else:
		print(2 * (x + y))
		print('L' * x + 'U' * y + 'R' * x + 'D' * y)


for _ in range(int(input())):
	s = input()
	l = 0
	r = 0
	u = 0
	d = 0
	st = list(set(s))
	if len(st) == 4:
		for i in s:
			if i == 'L':
				l += 1
			elif i == 'R':
				r += 1
			elif i == 'U':
				u += 1
			elif i == 'D':
				d += 1
		if l > r:
			count = r
			ans1 = 'R' * r
			ans2 = 'L' * r
		else:
			count = l
			ans1 = 'R' * l
			ans2 = 'L' * l
		if u > d:
			count += d
			ans3 = 'U' * d
			ans4 = 'D' * d
		else:
			count += u
			ans3 = 'U' * u
			ans4 = 'D' * u
		print(2 * count)
		print(ans2 + ans3 + ans1 + ans4)
	elif len(st) == 2:
		if st[0] == 'L' and st[1] == 'R':
			print(2)
			print('LR')
		elif st[0] == 'R' and st[1] == 'L':
			print(2)
			print('LR')
		elif st[0] == 'U' and st[1] == 'D':
			print(2)
			print('UD')
		elif st[0] == 'D' and st[1] == 'U':
			print(2)
			print('UD')
		else:
			print(0)
	elif len(st) == 3:
		if 'L' not in st:
			print(2)
			print('UD')
		elif 'R' not in st:
			print(2)
			print('UD')
		elif 'U' not in st:
			print(2)
			print('LR')
		elif 'D' not in st:
			print(2)
			print('LR')
	else:
		print(0)


from collections import Counter
res = []
for _ in range(int(input())):
	cnt = Counter(input() + 'LRUD')
	a = min(cnt['L'], cnt['R']) - 1
	b = min(cnt['U'], cnt['D']) - 1
	if min(a, b) > 0:
		res.append(2 * (a + b))
		res.append('L' * a + 'U' * b + 'R' * a + 'D' * b)
	elif a > 0:
		res.append(2)
		res.append('LR')
	elif b > 0:
		res.append(2)
		res.append('UD')
	else:
		res.append(0)
		res.append('')
print(*res, sep='\n')


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
for _ in range(ii()):
	a = []
	s = input('')
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	n = min(l, r)
	p = min(u, d)
	for i in range(0, n):
		a.append('L')
	for i in range(0, p):
		a.append('U')
	for i in range(0, n):
		a.append('R')
	for i in range(0, p):
		a.append('D')
	if n == 0:
		if p == 0:
			print(0)
		else:
			print(2)
			print('UD')
	elif p == 0:
		print(2)
		print('LR')
	else:
		print(len(a))
		print(''.join(a))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
import datetime, math, functools
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(int(input())):
		s = input()
		nu = 0
		nd = 0
		nr = 0
		nl = 0
		for i in range(len(s)):
			if s[i] == 'U':
				nu += 1
			if s[i] == 'D':
				nd += 1
			if s[i] == 'R':
				nr += 1
			if s[i] == 'L':
				nl += 1
		z = min(nl, nr)
		k = min(nu, nd)
		if z == 0 and k == 0:
			print(0)
		else:
			if z == 0:
				v = 'UD'
			elif k == 0:
				v = 'LR'
			else:
				v = z * 'L' + k * 'U' + z * 'R' + k * 'D'
			print(len(v))
			print(v)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


q = int(input())
for i in range(q):
	s = input()
	h = min(s.count('L'), s.count('R'))
	v = min(s.count('U'), s.count('D'))
	if v == 0 and h == 0:
		print(0)
		print()
		continue
	if v == 0:
		print(2)
		print('LR')
		continue
	if h == 0:
		print(2)
		print('UD')
		continue
	print(v * 2 + h * 2)
	print('L' * h + 'U' * v + 'R' * h + 'D' * v)


t = int(input())
while t:
	a = input()
	L = []
	R = []
	U = []
	D = []
	for c in a:
		if c == 'D':
			D.append('D')
		elif c == 'U':
			U.append('U')
		elif c == 'L':
			L.append('L')
		elif c == 'R':
			R.append('R')
	if len(L) != len(R):
		if len(L) < len(R):
			R = ['R'] * len(L)
		else:
			L = ['L'] * len(R)
	if len(U) != len(D):
		if len(U) < len(D):
			D = ['D'] * len(U)
		else:
			U = ['U'] * len(D)
	g = ''
	if len(U) == 0:
		if len(R) > 0:
			g = 'LR'
	elif len(R) == 0:
		if len(U) > 0:
			g = 'UD'
	else:
		g += ''.join(L)
		g += ''.join(U)
		g += ''.join(R)
		g += ''.join(D)
	print(len(g))
	print(g)
	t = t - 1


for _ in range(int(input())):
	s = input()
	dirs = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for c in s:
		dirs[c] += 1
	(hor, vert) = (min(dirs['L'], dirs['R']), min(dirs['U'], dirs['D']))
	if not hor:
		if not vert:
			print(0)
		else:
			print(2)
			print('UD')
	elif not vert:
		print(2)
		print('LR')
	else:
		print(2 * (hor + vert))
		print('L' * hor + 'U' * vert + 'R' * hor + 'D' * vert)


a = int(input())
L = 0
R = 0
U = 0
D = 0
ans1 = ''
ans = 0
check = 0
for i in range(a):
	p = input()
	for j in range(len(p)):
		if p[j] == 'L':
			L += 1
		if p[j] == 'R':
			R += 1
		if p[j] == 'U':
			U += 1
		if p[j] == 'D':
			D += 1
	ans1 = 'L' * min(L, R) + 'U' * min(U, D) + 'R' * min(L, R) + 'D' * min(U, D)
	ans = 2 * (min(L, R) + min(U, D))
	if min(U, D) == 0 or min(L, R) == 0:
		if min(U, D) == 0:
			if min(L, R) == 0:
				print(0)
				check += 1
			else:
				print(2)
				print('LR')
		if min(L, R) == 0:
			if min(U, D) == 0:
				if check == 0:
					print(0)
			else:
				print(2)
				print('UD')
	else:
		print(ans)
		print(ans1)
	L = 0
	R = 0
	U = 0
	D = 0
	check = 0


q = int(input())
for w in range(0, q):
	ins = input()
	op = {'L': 0, 'U': 0, 'R': 0, 'D': 0}
	for i in ins:
		op[i] += 1
	op['L'] = min(op['L'], op['R'])
	op['R'] = op['L']
	op['U'] = min(op['U'], op['D'])
	op['D'] = op['U']
	if op['D'] == 0:
		op['L'] = min(1, op['L'])
		op['R'] = op['L']
	if op['L'] == 0:
		op['U'] = min(1, op['U'])
		op['D'] = op['U']
	print(sum(op.values()))
	for (i, j) in op.items():
		for k in range(0, j):
			print(i, end='')
	print('')


def solve():
	ss = list(input())
	l = ss.count('L')
	r = ss.count('R')
	u = ss.count('U')
	d = ss.count('D')
	lr = min(l, r)
	ud = min(u, d)
	if lr == 0 and ud == 0:
		print(0, '', sep='\n')
		return
	if lr == 0:
		print(2, 'UD', sep='\n')
		return
	if ud == 0:
		print(2, 'LR', sep='\n')
		return
	ans = 'L' * lr + 'U' * ud + 'R' * lr + 'D' * ud
	print(len(ans), ans, sep='\n')
t = int(input())
for i in range(t):
	solve()


def robot(strs):
	dicts = {'L': 'R', 'U': 'D'}
	lst = [i for i in strs]
	l = lst.count('L')
	r = lst.count('R')
	u = lst.count('U')
	d = lst.count('D')
	l = r = left = min(l, r)
	u = d = up = min(u, d)
	res = []
	if l > 0 and u > 0:
		vs = 'LR'
		vt = 'UD'
		for i in range(l):
			res.append('L')
		for i in range(u):
			res.append('U')
		for i in range(l):
			res.append('R')
		for i in range(u):
			res.append('D')
	else:
		if l == u == 0:
			print(0)
			return ' '
		if l == 0:
			res = ['U', 'D']
		if u == 0:
			res = ['L', 'R']
	print(len(res))
	return ''.join(res)

def main():
	n = eval(input())
	for i in range(n):
		x = input()
		print(robot(x))
main()


t = int(input())
import collections
for i in range(t):
	directions = input()
	nums = [0, 0, 0, 0]
	for char in directions:
		if char == 'L':
			nums[0] += 1
		elif char == 'R':
			nums[1] += 1
		elif char == 'U':
			nums[2] += 1
		else:
			nums[3] += 1
	y = len(directions) - (abs(nums[0] - nums[1]) + abs(nums[2] - nums[3]))
	nums[0] = min(nums[1], nums[0])
	nums[1] = min(nums[1], nums[0])
	nums[2] = min(nums[2], nums[3])
	nums[3] = min(nums[2], nums[3])
	if nums[0] == 0:
		x = min(1, nums[2])
		test = x * 'U' + x * 'D'
		print(len(test))
		print(test)
		continue
	if nums[2] == 0:
		x = min(1, nums[0])
		test = x * 'L' + x * 'R'
		print(len(test))
		print(test)
		continue
	result = nums[0] * 'L' + nums[2] * 'U' + nums[1] * 'R' + nums[3] * 'D'
	print(y)
	print(result)


import sys
for _ in range(int(sys.stdin.readline())):
	s = sys.stdin.readline().strip()
	r = s.count('R')
	l = s.count('L')
	u = s.count('U')
	d = s.count('D')
	ct = l + r + u + d
	(l, r) = (min(l, r), min(l, r))
	(u, d) = (min(u, d), min(u, d))
	ct -= l + u + r + d
	ans = 'L' * l + 'U' * u + 'R' * r + 'D' * d
	if u == 0 and l > 1:
		ans = 'LR'
	if l == 0 and u > 1:
		ans = 'UD'
	print(len(ans))
	print(ans)


for _ in range(int(input())):
	s = input()
	d = {}
	for i in range(len(s)):
		try:
			d[s[i]] += 1
		except:
			d[s[i]] = 1
	if len(d) == 1:
		print('0')
		print()
	elif len(d) == 2:
		l = []
		for i in d.keys():
			l.append(i)
		l.sort()
		if l == ['L', 'R']:
			print(2)
			print('LR')
		elif l == ['D', 'U']:
			print(2)
			print('UD')
		else:
			print(0)
			print()
	elif len(d) == 3:
		l = []
		for i in d.keys():
			l.append(i)
		l.sort()
		if l == ['L', 'R', 'U'] or l == ['D', 'L', 'R']:
			print(2)
			print('LR')
		elif l == ['D', 'L', 'U'] or l == ['D', 'R', 'U']:
			print(2)
			print('UD')
	else:
		a1 = a2 = a3 = a4 = 0
		for i in d.keys():
			if i == 'L':
				a1 += d[i]
			elif i == 'R':
				a2 += d[i]
			elif i == 'U':
				a3 += d[i]
			elif i == 'D':
				a4 += d[i]
		a = min(a1, a2)
		b = min(a3, a4)
		an = a * 'L' + b * 'U' + a * 'R' + b * 'D'
		print(a * 2 + b * 2)
		print(an)


t = int(input())
for t in range(t):
	s = input()
	cnt_L = s.count('L')
	cnt_R = s.count('R')
	cnt_U = s.count('U')
	cnt_D = s.count('D')
	if len(s) == 1:
		y = ''
	elif min(cnt_D, cnt_U) == 0 and min(cnt_L, cnt_R) == 0:
		y = ''
	elif min(cnt_D, cnt_U) == 0:
		y = 'LR'
	elif min(cnt_L, cnt_R) == 0:
		y = 'UD'
	else:
		x = min(cnt_L, cnt_R)
		z = min(cnt_D, cnt_U)
		y = 'L' * x + 'U' * z + 'R' * x + 'D' * z
	print(len(y))
	print(y)


def solve():
	s = input()
	l = {'L': 0, 'U': 0, 'R': 0, 'D': 0}
	for values in s:
		l[values] += 1
	if l['L'] >= l['R']:
		l['L'] = l['R']
	else:
		l['R'] = l['L']
	if l['U'] >= l['D']:
		l['U'] = l['D']
	else:
		l['D'] = l['U']
	if l['U'] == 0:
		if l['R'] >= 1:
			print(2)
			print('LR')
			return
	if l['R'] == 0:
		if l['U'] >= 1:
			print(2)
			print('UD')
			return
	print(l['R'] + l['L'] + l['U'] + l['D'])
	res = ''
	for values in l.keys():
		for i in range(l[values]):
			print(values, end='')
	print()
t = int(input())
while t > 0:
	solve()
	t -= 1


for _ in range(int(input())):
	s = input()
	l = 0
	r = 0
	u = 0
	d = 0
	for i in range(len(s)):
		if s[i] == 'L':
			l += 1
		elif s[i] == 'R':
			r += 1
		elif s[i] == 'U':
			u += 1
		else:
			d += 1
	x = abs(l - r)
	y = abs(u - d)
	rem = x + y
	if l > r:
		l = l - x
	else:
		r = r - x
	if u > d:
		u = u - y
	else:
		d = d - y
	l1 = ['L'] * l
	r1 = ['R'] * r
	d1 = ['D'] * d
	u1 = ['U'] * u
	ans = ''.join(l1 + u1 + r1 + d1)
	if l == r and (u == 0 and d == 0) and (l > 0):
		ans = 'LR'
	elif u == d and (l == 0 and r == 0) and (u > 0):
		ans = 'UD'
	print(len(ans))
	print(ans)


for _ in range(int(input())):
	a = input()
	alpha = 0
	beta = 0
	gamma = 0
	delta = 0
	for i in a:
		if i == 'U':
			alpha += 1
		elif i == 'D':
			beta += 1
		elif i == 'L':
			gamma += 1
		elif i == 'R':
			delta += 1
	if min(alpha, beta) == 0:
		if min(gamma, delta) != 0:
			print(2)
			print('LR')
		else:
			print(0)
	elif min(gamma, delta) == 0:
		if min(alpha, beta) != 0:
			print(2)
			print('UD')
		else:
			print(0)
	else:
		omega = min(alpha, beta)
		theta = min(gamma, delta)
		print(2 * omega + 2 * theta)
		print('L' * theta, end='')
		print('U' * omega, end='')
		print('R' * theta, end='')
		print('D' * omega)


def RI():
	return list(map(int, input().split()))

def solve():
	S = input()
	dic = dict()
	for i in S:
		if i not in dic:
			dic[i] = 1
		else:
			dic[i] += 1
	lr = min(dic.get('L', 0), dic.get('R', 0))
	ud = min(dic.get('U', 0), dic.get('D', 0))
	if lr == 0 and ud == 0:
		print(0)
		print()
		return
	if ud == 0:
		print(2)
		print('LR')
	elif lr == 0:
		print(2)
		print('UD')
	else:
		ans = ''
		ans += 'L' * lr
		ans += 'U' * ud
		ans += 'R' * lr
		ans += 'D' * ud
		print(len(ans))
		print(ans)
(n_case,) = RI()
for _ in range(n_case):
	solve()


from collections import defaultdict
t = int(input())
while t > 0:
	t -= 1
	s = input()
	l = 0
	r = 0
	u = 0
	d = 0
	for i in s:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		elif i == 'D':
			d += 1
	x = min(l, r)
	y = min(u, d)
	ans = ''
	z = 0
	if x == 0 and y != 0:
		ans = 'UD'
		z = 2
	elif y == 0 and x != 0:
		ans = 'LR'
		z = 2
	elif x == 0 and y == 0:
		ans = ' '
		z = 0
	else:
		for i in range(x):
			ans += 'L'
		for i in range(y):
			ans += 'U'
		for i in range(x):
			ans += 'R'
		for i in range(y):
			ans += 'D'
		z = 2 * (x + y)
	print(z)
	print(ans)


import math
import random

def type1():
	return map(int, input().split())

def type2():
	return list(type1())

def type3():
	return int(input())
for _ in range(type3()):
	s = input()
	(U, D, L, R) = (s.count('U'), s.count('D'), s.count('L'), s.count('R'))
	horizontal = min(L, R)
	vertical = min(U, D)
	if vertical >= 1 and horizontal == 0:
		print(2)
		print('UD')
	elif horizontal >= 1 and vertical == 0:
		print(2)
		print('LR')
	elif vertical < 1 or horizontal < 1:
		print(0)
	elif vertical >= 1 and horizontal >= 1:
		print(2 * (vertical + horizontal))
		print('L' * horizontal + 'U' * vertical + 'R' * horizontal + 'D' * vertical)


from sys import stdin, stdout
from os import path
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
for _ in range(int(stdin.readline())):
	x = stdin.readline()
	u = l = r = d = 0
	for i in x:
		if i == 'U':
			u += 1
		elif i == 'D':
			d += 1
		elif i == 'L':
			l += 1
		elif i == 'R':
			r += 1
	tem1 = min(l, r)
	tem2 = min(u, d)
	if tem1 == 0 and tem2 > 1:
		tem2 = 1
	if tem1 > 1 and tem2 == 0:
		tem1 = 1
	out = tem2 + tem1
	st = 'L' * tem1 + 'U' * tem2 + 'R' * tem1 + 'D' * tem2
	print(out * 2)
	print(st)


def col(x, a):
	k = 0
	for el in a:
		if x == el:
			k += 1
	return k
q = int(input())
for i in range(q):
	s = input()
	nl = col('L', s)
	nr = col('R', s)
	nu = col('U', s)
	nd = col('D', s)
	nl = min(nl, nr)
	nr = nl
	nu = min(nu, nd)
	nd = nu
	if nl == 0 and nu == 0:
		print(0)
		continue
	elif nl == 0:
		print(2)
		print('UD')
		continue
	elif nu == 0:
		print(2)
		print('LR')
		continue
	print((nl + nu) * 2)
	print(nl * 'L' + nu * 'U' + nr * 'R' + nd * 'D')


for i in range(int(input())):
	s = list(input())
	L = s.count('L')
	R = s.count('R')
	U = s.count('U')
	D = s.count('D')
	l = min(L, R)
	u = min(U, D)
	if u == 0:
		l = min(1, l)
	if l == 0:
		u = min(1, u)
	print(2 * (l + u))
	print('L' * l + 'U' * u + 'R' * l + 'D' * u)


for i in range(int(input())):
	s = input()
	x = min(s.count('L'), s.count('R'))
	y = min(s.count('U'), s.count('D'))
	if x == 0 and y > 0:
		print(2)
		print('UD')
	elif x > 0 and y == 0:
		print(2)
		print('LR')
	elif x == 0 and y == 0:
		print(0)
		print()
	else:
		print(2 * x + 2 * y)
		for h in range(x):
			print('L', end='')
		for h in range(y):
			print('U', end='')
		for h in range(x):
			print('R', end='')
		for h in range(y):
			print('D', end='')
		print()


from collections import Counter, defaultdict
q = int(input())
while q:
	path = list(input())
	freq = Counter(path)
	lr = min(freq.get('L', 0), freq.get('R', 0))
	ud = min(freq.get('U', 0), freq.get('D', 0))
	if lr == 0 and ud == 0:
		print(0)
		print('')
	elif lr == 0:
		print(2)
		print('UD')
	elif ud == 0:
		print(2)
		print('LR')
	else:
		ans = ''.join(['L'] * lr + ['U'] * ud + ['R'] * lr + ['D'] * ud)
		print(len(ans))
		print(ans)
	q -= 1


for _ in range(int(input())):
	commands = input()
	L = R = U = D = 0
	for command in commands:
		if command == 'L':
			L += 1
		elif command == 'R':
			R += 1
		elif command == 'U':
			U += 1
		else:
			D += 1
	L = R = min(L, R)
	U = D = min(U, D)
	if L > 0 and U > 0:
		print(L + R + U + D)
		newcommand = 'L' * L + 'U' * U + 'R' * R + 'D' * D
	elif L and (not U):
		print(2)
		newcommand = 'LR'
	elif U:
		print(2)
		newcommand = 'UD'
	else:
		print(0)
		newcommand = ''
	print(newcommand)


n = int(input())
for i in range(n):
	s = input()
	l = len(s)
	L = s.count('L')
	R = s.count('R')
	D = s.count('D')
	U = l - L - R - D
	if U == 0 or D == 0:
		if L == 0 or R == 0:
			print(0)
		else:
			print(2)
			print('LR')
	elif L == 0 or R == 0:
		print(2)
		print('UD')
	else:
		print(l - abs(R - L) - abs(U - D))
		ud = min(U, D)
		lr = min(L, R)
		print('L' * lr + 'U' * ud + 'R' * lr + 'D' * ud)


for i in range(int(input())):
	k = input()
	(a, b, c, d) = (k.count('L'), k.count('U'), k.count('R'), k.count('D'))
	(g, h) = (min(a, c), min(b, d))
	if g == 0 and h == 0:
		print(0)
	elif g == 0:
		print(2)
		print('UD')
	elif h == 0:
		print(2)
		print('LR')
	else:
		print(2 * (g + h))
		print('L' * g + 'U' * h + 'R' * g + 'D' * h)


q = int(input())
for it in range(q):
	A = [0] * 4
	s = input()
	for i in s:
		if i == 'U':
			A[0] += 1
		if i == 'R':
			A[1] += 1
		if i == 'D':
			A[2] += 1
		if i == 'L':
			A[3] += 1
	ud = min(A[0], A[2])
	lr = min(A[1], A[3])
	ans = ''
	sum = 0
	if ud > 0 and lr > 0:
		sum = (ud + lr) * 2
	elif ud > 0 or lr > 0:
		if ud > lr:
			ud = 1
		else:
			lr = 1
		sum = (ud + lr) * 2
	else:
		sum = 0
	print(sum)
	if sum > 0:
		for i in range(lr):
			ans += 'L'
		for i in range(ud):
			ans += 'U'
		for i in range(lr):
			ans += 'R'
		for i in range(ud):
			ans += 'D'
		print(ans)


q = int(input())
while q:
	s = str(input())
	le = len(s)
	cnt = [0, 0, 0, 0]
	for i in range(le):
		if s[i] == 'L':
			cnt[0] += 1
		if s[i] == 'R':
			cnt[1] += 1
		if s[i] == 'U':
			cnt[2] += 1
		if s[i] == 'D':
			cnt[3] += 1
	val1 = min(cnt[0], cnt[1])
	val2 = min(cnt[2], cnt[3])
	if val1 == val2:
		print(4 * val1)
		val = val1
		for i in range(val):
			print('L', end='')
		for i in range(val):
			print('U', end='')
		for i in range(val):
			print('R', end='')
		for i in range(val):
			print('D', end='')
		print()
	if val1 < val2:
		if val1 == 0:
			print(2)
			print('UD')
		else:
			print(2 * (val1 + val2))
			for i in range(val1):
				print('L', end='')
			for i in range(val2):
				print('U', end='')
			for i in range(val1):
				print('R', end='')
			for i in range(val2):
				print('D', end='')
			print()
	if val2 < val1:
		if val2 == 0:
			print(2)
			print('LR')
		else:
			print(2 * (val1 + val2))
			for i in range(val1):
				print('L', end='')
			for i in range(val2):
				print('U', end='')
			for i in range(val1):
				print('R', end='')
			for i in range(val2):
				print('D', end='')
			print()
	q -= 1


from sys import stdin, stdout
for tc in range(int(stdin.readline())):
	s = stdin.readline()
	(U, D, L, R) = (s.count('U'), s.count('D'), s.count('L'), s.count('R'))
	U = D = min(U, D)
	L = R = min(L, R)
	if U == 0:
		L = R = min(L, 1)
	if L == 0:
		U = D = min(U, 1)
	stdout.write(str(U + D + L + R) + '\n')
	stdout.write(''.join(['L'] * L + ['U'] * U + ['R'] * R + ['D'] * D) + '\n')


from sys import stdin
q = int(stdin.readline().strip())
for _ in range(q):
	string = stdin.readline().strip()
	(l, r, u, d) = (0, 0, 0, 0)
	for i in string:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	l = min(l, r)
	r = l
	u = min(u, d)
	d = u
	if l == 0 and u >= 1:
		print(2)
		print('UD')
	elif u == 0 and l >= 1:
		print(2)
		print('LR')
	else:
		print(l + d + u + r)
		print('L' * l + 'U' * u + 'R' * r + 'D' * d)


from collections import Counter
for i in range(int(input())):
	count = Counter(input())
	lr = min(count['L'], count['R'])
	ud = min(count['U'], count['D'])
	if lr == ud == 0:
		print(0)
	elif lr == 0:
		print(2)
		print('UD')
	elif ud == 0:
		print(2)
		print('LR')
	else:
		print(lr + ud << 1)
		print('L' * lr + 'U' * ud + 'R' * lr + 'D' * ud)