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".

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms

Implementation

Constructive algorithms


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')


def main(MOVE):
	r = MOVE.count('R')
	l = MOVE.count('L')
	d = MOVE.count('D')
	u = MOVE.count('U')
	x = min([l, r])
	y = min([u, d])
	if y == 0:
		x = min([x, 1])
	if x == 0:
		y = min([y, 1])
	ans = ['R'] * x
	ans += ['U'] * y
	ans += ['L'] * x
	ans += ['D'] * y
	print((x + y) * 2)
	print(''.join(ans))

def runner():
	val = input()
	x = []
	for i in range(int(val)):
		ans = input()
		x.append(ans)
	for i in range(int(val)):
		main(x[i])
runner()


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()


n = int(input())
for i in range(n):
	s = input()
	(l, r, u, d) = (0, 0, 0, 0)
	for v in s:
		if v == 'L':
			l += 1
		if v == 'R':
			r += 1
		if v == 'U':
			u += 1
		if v == 'D':
			d += 1
	if l == 0 or r == 0:
		if u and d:
			print(2)
			print('UD')
		else:
			print(0)
	elif u == 0 or d == 0:
		if l and r:
			print(2)
			print('LR')
		else:
			print(0)
	else:
		x = min(l, r)
		y = min(u, d)
		f = 'R' * x + 'U' * y + 'L' * x + 'D' * y
		print(len(f))
		print(f)


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')


import sys
ip = lambda : sys.stdin.readline().rstrip()
from collections import Counter
for _ in range(int(ip())):
	s = ip().lower()
	if s == '':
		print(0)
		print()
	d = Counter(s)
	if 'l' in d:
		if 'r' not in d:
			d.pop('l')
	elif 'r' in d:
		d.pop('r')
	if 'u' in d:
		if 'd' not in d:
			d.pop('u')
	elif 'd' in d:
		d.pop('d')
	ans = ''
	if len(d) == 2:
		ans = ''.join(list(d.keys()))
		ans = ans.upper()
	else:
		(v1, v2) = (min(d['r'], d['l']), min(d['u'], d['d']))
		ans += 'R' * v1 + 'D' * v2 + 'L' * v1 + 'U' * v2
	print(len(ans))
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	a = s.count('L')
	b = s.count('R')
	c = s.count('D')
	d = s.count('U')
	if min(a, b) == 0 and min(c, d) == 0:
		print('0')
	elif c == 0 or d == 0:
		print('2')
		print('LR')
	elif a == 0 or b == 0:
		print('2')
		print('UD')
	else:
		x = min(a, b)
		y = min(c, d)
		print(x + y + x + y)
		q = ''
		for i in range(x):
			q += 'R'
		for i in range(y):
			q += 'D'
		for i in range(x):
			q += 'L'
		for i in range(y):
			q += 'U'
		print(q)


tc = int(input())
for i in range(tc):
	cmds = input()
	l = 0
	r = 0
	u = 0
	d = 0
	for c in cmds:
		if c == 'L':
			l += 1
		elif c == 'R':
			r += 1
		elif c == 'U':
			u += 1
		else:
			d += 1
	lf = min(l, r)
	ud = min(u, d)
	if lf > 0 and ud > 0 or (lf == 0 and ud > 0) or (lf > 0 and ud == 0):
		if lf == 0:
			ud = 1
		if ud == 0:
			lf = 1
		res = ''
		l = lf
		r = lf
		u = ud
		d = ud
		for i in range(l):
			res += 'L'
		for i in range(d):
			res += 'D'
		for i in range(r):
			res += 'R'
		for i in range(u):
			res += 'U'
		print(len(res))
		print(res)
	else:
		print(0)


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)


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


for i in range(int(input())):
	arr = input()
	(a, b, c, d) = (arr.count('L'), arr.count('R'), arr.count('U'), arr.count('D'))
	rs = 2 * (min(a, b) + min(c, d))
	if rs != 0:
		if min(a, b) == 0:
			print('2\nUD')
		elif min(c, d) == 0:
			print('2\nLR')
		else:
			print(rs, '\n' + min(a, b) * 'L' + min(c, d) * 'U' + min(a, b) * 'R' + min(c, d) * 'D')
	else:
		print(0)


t = int(input())
while t != 0:
	t -= 1
	s = input()
	(u, d, l, r) = (0, 0, 0, 0)
	for i in range(len(s)):
		if s[i] == 'U':
			u += 1
		if s[i] == 'D':
			d += 1
		if s[i] == 'L':
			l += 1
		if s[i] == 'R':
			r += 1
	x = []
	x.append(u)
	x.append(d)
	x.append(l)
	x.append(r)
	x.sort()
	if x[0] == x[1] and x[1] == x[2] and (x[1] == 0):
		print(0)
		print()
	elif x[0] == x[1] and x[1] == 0:
		if u == 0 and d != 0 or (d == 0 and u != 0) or (l == 0 and r != 0) or (r == 0 and l != 0):
			print(0)
		elif u == 0 and d == 0:
			print(2)
			print('LR')
		elif l == 0 and r == 0:
			print(2)
			print('UD')
	elif x[0] == 0:
		if u == 0 or d == 0:
			print(2)
			print('LR')
		else:
			print(2)
			print('UD')
	else:
		if u == d and l == r:
			print(u * 2 + l * 2)
		else:
			print(2 * min(u, d) + 2 * min(l, r))
		ans = ''
		for i in range(min(r, l)):
			ans += 'R'
		for i in range(min(u, d)):
			ans += 'U'
		for i in range(min(r, l)):
			ans += 'L'
		for i in range(min(u, d)):
			ans += 'D'
		print(ans)


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)


for _ in range(int(input())):
	arr = [0, 0, 0, 0]
	s = input()
	for v in s:
		if v == 'U':
			arr[0] += 1
		elif v == 'D':
			arr[1] += 1
		elif v == 'L':
			arr[2] += 1
		else:
			arr[3] += 1
	ver = min(arr[0], arr[1])
	ho = min(arr[2], arr[3])
	arr[0] = ver
	arr[1] = ho
	arr[2] = ver
	arr[3] = ho
	total = 2 * ver + 2 * ho
	c = ['U', 'L', 'D', 'R']
	t = ''
	reserve = []
	i = 0
	for i in range(4):
		t += c[i] * arr[i]
	if 'LR' in t:
		print(2)
		print('LR')
	elif 'RL' in t:
		print(2)
		print('RL')
	elif 'UD' in t:
		print(2)
		print('UD')
	elif 'DU' in t:
		print(2)
		print('DP')
	else:
		print(len(t))
		print(t)


q = int(input())
for _ in range(q):
	s = list(input())
	s.sort()
	d = 0
	l = 0
	r = 0
	u = 0
	for i in range(len(s)):
		if s[i] == 'D':
			d += 1
		if s[i] == 'R':
			r += 1
		if s[i] == 'L':
			l += 1
		if s[i] == 'U':
			u += 1
	x = 2 * min(u, d)
	y = 2 * min(l, r)
	a = ''
	if y == 0 and x > 0:
		print(2)
		print('UD')
	elif x == 0 and y > 0:
		print(2)
		print('LR')
	else:
		print(x + y)
		for i in range(x // 2):
			a += 'U'
		for i in range(y // 2):
			a += 'R'
		for i in range(x // 2):
			a += 'D'
		for i in range(y // 2):
			a += 'L'
		print(a)


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)


q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	arr = []
	(c_L, c_R, c_D, c_U) = (0, 0, 0, 0)
	for i in s:
		arr.append(i)
		if i == 'L':
			c_L = c_L + 1
		elif i == 'R':
			c_R = c_R + 1
		elif i == 'D':
			c_D = c_D + 1
		elif i == 'U':
			c_U = c_U + 1
	y = min(c_D, c_U)
	x = min(c_L, c_R)
	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(x * 'L' + y * 'D' + x * 'R' + y * 'U')


q = int(input())
for _ in range(q):
	s = input()
	LENGTH = len(s)
	(us, ds, ls, rs) = (s.count('U'), s.count('D'), s.count('L'), s.count('R'))
	if us != ds:
		if us > ds:
			LENGTH = LENGTH - (us - ds)
			us = ds
		else:
			LENGTH = LENGTH - (ds - us)
			ds = us
	if ls != rs:
		if ls > rs:
			LENGTH = LENGTH - (ls - rs)
			ls = rs
		else:
			LENGTH = LENGTH - (rs - ls)
			rs = ls
	if us == 0 and (rs != 0 or ls != 0):
		LENGTH = 2
		(rs, ls) = (1, 1)
	if rs == 0 and (us != 0 or ds != 0):
		LENGTH = 2
		(us, ds) = (1, 1)
	print(LENGTH)
	print('U' * us + 'R' * rs + 'D' * ds + 'L' * ls)


q = int(input())
for _ in range(q):
	s = input()
	lr = min(s.count('L'), s.count('R'))
	ud = min(s.count('U'), s.count('D'))
	ans = 2 * lr + 2 * ud
	t = set(s)
	if ans == 0 or len(t) < 2:
		print(0)
	elif len(t) < 4:
		if 'L' in t and 'R' in t:
			print(2)
			print('LR')
		else:
			print(2)
			print('UD')
	else:
		print(ans)
		res = ''
		res += 'R' * lr
		res += 'U' * ud
		res += 'L' * lr
		res += 'D' * ud
		print(res)


import sys
input = sys.stdin.readline

def getAns(k):
	r = 0
	l = 0
	u = 0
	d = 0
	for i in k:
		if i == 'D':
			d += 1
		elif i == 'U':
			u += 1
		elif i == 'R':
			r += 1
		elif i == 'L':
			l += 1
	r = min(r, l)
	u = min(u, d)
	if r == 0 or u == 0:
		if r == 0 and u == 0:
			sys.stdout.write('0\n')
		elif r == 0:
			sys.stdout.write('2\n')
			sys.stdout.write('UD')
		else:
			sys.stdout.write('2\n')
			sys.stdout.write('LR')
	else:
		sys.stdout.write(str(2 * r + 2 * u) + '\n')
		for i in range(r):
			sys.stdout.write('R')
		for i in range(u):
			sys.stdout.write('U')
		for i in range(r):
			sys.stdout.write('L')
		for i in range(u):
			sys.stdout.write('D')
n = int(input())
for i in range(n):
	getAns(list(input()))
	if not i == n - 1:
		sys.stdout.write('\n')


n = int(input())
result = []
for i in range(n):
	s = input()
	(nou, nod, nor, nol) = (0, 0, 0, 0)
	for i in s:
		if i == 'L':
			nol += 1
		if i == 'R':
			nor += 1
		if i == 'U':
			nou += 1
		if i == 'D':
			nod += 1
	l = [nor, nol, nod, nou]
	if 0 not in l:
		a = max(nou, nod) - min(nou, nod)
		b = max(nol, nor) - min(nol, nor)
		result.append(len(s) - a - b)
		ans = min(nou, nod) * 'U' + min(nol, nor) * 'L' + min(nou, nod) * 'D' + min(nol, nor) * 'R'
		result.append(ans)
		pass
	elif nor == 0 and nod != 0 and (nol != 0) and (nou != 0) or (nor != 0 and nod == 0 and (nol != 0) and (nou != 0)) or (nor != 0 and nod != 0 and (nol == 0) and (nou != 0)) or (nor != 0 and nod != 0 and (nol != 0) and (nou == 0)):
		result.append(2)
		if nor == 0 or nol == 0:
			result.append('DU')
		if nod == 0 or nou == 0:
			result.append('LR')
		pass
	elif nor == 0 and nod == 0 and (nol != 0) and (nou != 0):
		result.append(0)
	elif nor == 0 and nou == 0 and (nol != 0) and (nod != 0):
		result.append(0)
	elif nol == 0 and nod == 0 and (nor != 0) and (nou != 0):
		result.append(0)
	elif nol == 0 and nou == 0 and (nor != 0) and (nod != 0):
		result.append(0)
	elif nor == 0 and nol == 0 and (nod != 0) and (nou != 0):
		result.append(2)
		result.append('DU')
	elif nou == 0 and nod == 0 and (nol != 0) and (nor != 0):
		result.append(2)
		result.append('LR')
	elif nor == 0 and nod == 0 and (nol == 0) and (nou != 0):
		result.append(0)
	elif nor == 0 and nod == 0 and (nou == 0) and (nol != 0):
		result.append(0)
	elif nor == 0 and nou == 0 and (nol == 0) and (nod != 0):
		result.append(0)
	elif nou == 0 and nod == 0 and (nol == 0) and (nor != 0):
		result.append(0)
	elif nor == 0 and nod == 0 and (nol == 0) and (nou == 0):
		result.append(0)
for i in result:
	print(i)


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)


q = int(input())
text_list = []
for i in range(q):
	text_list.append(input())
for one_text in text_list:
	L_count = one_text.count('L')
	R_count = one_text.count('R')
	U_count = one_text.count('U')
	D_count = one_text.count('D')
	if R_count == 0 or L_count == 0:
		if U_count == 0 or D_count == 0:
			print(0)
		else:
			print(2)
			print('UD')
	elif U_count == 0 or D_count == 0:
		if R_count == 0 or L_count == 0:
			print(0)
		else:
			print(2)
			print('LR')
	else:
		a = min(L_count, R_count)
		b = min(U_count, D_count)
		print(a * 2 + b * 2)
		print('U' * b + 'L' * a + 'D' * b + 'R' * a)


import sys
t = int(sys.stdin.readline().strip())
for i in range(t):
	a = sys.stdin.readline().strip()
	l = 0
	r = 0
	d = 0
	u = 0
	for j in a:
		if j == 'L':
			l += 1
		elif j == 'R':
			r += 1
		elif j == 'D':
			d += 1
		elif j == 'U':
			u += 1
	x = min(l, r)
	y = min(u, d)
	op = []
	if x > 0 and y > 0:
		for k in range(y):
			op.append('U')
		for k in range(x):
			op.append('R')
		for k in range(y):
			op.append('D')
		for k in range(x):
			op.append('L')
		print(len(op))
		print(''.join(op))
	elif y > 0:
		print(2)
		print('UD')
	elif x > 0:
		print(2)
		print('LR')
	else:
		print(0)


q = int(input())
for _ in range(q):
	commands = input()
	cnt_U = cnt_D = cnt_R = cnt_L = 0
	for command in commands:
		if command == 'U':
			cnt_U += 1
		elif command == 'D':
			cnt_D += 1
		elif command == 'R':
			cnt_R += 1
		elif command == 'L':
			cnt_L += 1
	mini_Vert = min(cnt_U, cnt_D)
	mini_Gor = min(cnt_R, cnt_L)
	if mini_Gor * mini_Vert != 0:
		print(mini_Gor * 2 + mini_Vert * 2)
		print('R' * mini_Gor + 'D' * mini_Vert + 'L' * mini_Gor + 'U' * mini_Vert)
	elif mini_Vert != 0:
		print(2)
		print('DU')
	elif mini_Gor != 0:
		print(2)
		print('RL')
	else:
		print(0)


from collections import defaultdict as dc
import sys
import math
mod = 10 ** 9 + 7

def inp():
	p = int(input())
	return p

def line():
	p = list(map(int, input().split()))
	return p
for i in range(inp()):
	p = dc(int)
	s = str(input())
	n = len(s)
	ans = ''
	for i in range(n):
		p[s[i]] += 1
	l = p['L']
	r = p['R']
	u = p['U']
	d = p['D']
	x = min(l, r)
	y = min(u, d)
	if x == 0 and y == 0:
		print(0)
		print('')
	elif x == 0:
		print(2)
		print('UD')
	elif y == 0:
		print(2)
		print('LR')
	else:
		print(2 * (x + y))
		ans = 'R' * x + 'D' * y + 'L' * x + 'U' * y
		print(ans)


DIR = ((0, -1), (1, 0), (-1, 0), (1, 0))
SIG = {'L': 0, 'R': 1, 'U': 2, 'D': 3}
for case in range(int(input())):
	s = input()
	cnt = [0 for i in range(4)]
	for i in range(len(s)):
		cnt[SIG[s[i]]] += 1
	w = min(cnt[0], cnt[1])
	l = min(cnt[2], cnt[3])
	if w and l:
		print(2 * (w + l))
		for i in range(w):
			print('R', end='')
		for i in range(l):
			print('D', end='')
		for i in range(w):
			print('L', end='')
		for i in range(l):
			print('U', end='')
		print()
	elif w:
		print(2)
		print('LR')
	elif l:
		print(2)
		print('UD')
	else:
		print(0)


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')


t = int(input())
for i in range(t):
	l = input()
	d = {'U': 0, 'D': 0, 'R': 0, 'L': 0}
	x = 0
	y = 0
	for j in l:
		d[j] += 1
		if j == 'D':
			y -= 1
		if j == 'U':
			y += 1
		if j == 'R':
			x += 1
		if j == 'L':
			x -= 1
	if x > 0:
		d['R'] -= x
	if x < 0:
		d['L'] += x
	if y > 0:
		d['U'] -= y
	if y < 0:
		d['D'] += y
	a = ''
	c = 0
	for j in d:
		if d[j] == 0:
			c = 1
			break
	if c == 1:
		c = 0
		if d['U'] != 0:
			a = a + 'U'
			c = c + 1
		if d['D'] != 0:
			a = a + 'D'
			c = c + 1
		if d['R'] != 0:
			a = a + 'R'
			c = c + 1
		if d['L'] != 0:
			a = a + 'L'
			c = c + 1
		if c != 2:
			a = ''
			c = 0
	else:
		a = a + 'U' * d['U']
		c = d['U']
		a = a + 'L' * d['L']
		c = c + d['L']
		a = a + 'D' * d['D']
		c = c + d['D']
		a = a + 'R' * d['R']
		c = c + d['R']
	print(c)
	print(a)


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)


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


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))


from sys import stdin
input = stdin.readline
tc = int(input())
for i in range(tc):
	rob_mov = input()
	(U, L, D, R) = (rob_mov.count('U'), rob_mov.count('L'), rob_mov.count('D'), rob_mov.count('R'))
	(UD, LR) = (min(U, D), min(L, R))
	if UD == 0 and LR > 0:
		print('2\nLR')
	elif UD > 0 and LR == 0:
		print('2\nUD')
	else:
		print(len('U' * UD + 'L' * LR + 'D' * UD + 'R' * LR), '\n' + 'U' * UD + 'L' * LR + 'D' * UD + 'R' * LR)


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 _ in range(int(input())):
	s = input()
	a = s.count('L')
	b = s.count('R')
	c = s.count('U')
	d = s.count('D')
	if min([a, b, c, d]) == 0:
		if a > 0 and b > 0:
			print(2)
			print('RL')
		elif c > 0 and d > 0:
			print(2)
			print('UD')
		else:
			print(0)
			print()
	else:
		ans = 2 * (min(a, b) + min(c, d))
		print(ans)
		print(min(a, b) * 'R' + min(c, d) * 'U' + min(a, b) * 'L' + min(c, d) * 'D')


import sys, math

def input():
	return sys.stdin.readline()[:-1]

def main():
	q = int(input())
	for _ in range(q):
		s = input()
		(l, r, u, d) = (0, 0, 0, 0)
		for k in range(len(s)):
			if s[k] == 'L':
				l += 1
			elif s[k] == 'R':
				r += 1
			elif s[k] == 'U':
				u += 1
			else:
				d += 1
		lr = min(l, r)
		ud = min(u, d)
		if lr == 0 and ud >= 1:
			print(2)
			print('UD')
		elif ud == 0 and lr >= 1:
			print(2)
			print('LR')
		else:
			ans = 'R' * lr + 'D' * ud + 'L' * lr + 'U' * ud
			print(len(ans))
			print(ans)
main()


q = int(input())
for i in range(q):
	i = input()
	I = []
	I.extend(i)
	u = I.count('U')
	d = I.count('D')
	l = I.count('L')
	r = I.count('R')
	y = min(u, d)
	x = min(l, r)
	if y == 0:
		if x == 0:
			print('0')
			print('')
		else:
			print('2')
			print('LR')
	elif x == 0:
		if y == 0:
			print('0')
			print('')
		else:
			print('2')
			print('UD')
	else:
		print(2 * (x + y))
		print(y * 'U' + x * 'L' + y * 'D' + x * 'R')


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)


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')
testcases = int(input())
for j in range(testcases):
	string1 = [k for k in input()]
	dict1 = {'U': 0, 'L': 0, 'D': 0, 'R': 0}
	countu = 0
	countd = 0
	countl = 0
	countr = 0
	for s in range(len(string1)):
		if string1[s] == 'U':
			dict1['U'] += 1
			countu += 1
		elif string1[s] == 'D':
			dict1['D'] += 1
			countd += 1
		elif string1[s] == 'L':
			dict1['L'] += 1
			countl += 1
		else:
			dict1['R'] += 1
			countr += 1
	outy = ''
	if min(countl, countr) > 0 and min(countu, countd) > 0:
		for s in dict1.keys():
			if s == 'U' or s == 'D':
				string = s * min(countu, countd)
			else:
				string = s * min(countl, countr)
			outy += string
		print(2 * min(countu, countd) + 2 * min(countl, countr))
		print(outy)
	elif min(countl, countr) > 0 or min(countu, countd) > 0:
		print(2)
		if min(countu, countd) > 0:
			print('UD')
		else:
			print('LR')
	else:
		print(0)


q = int(input())
for i in range(q):
	s = input()
	d = dict()
	d[1] = 0
	d[-1] = 0
	d[2] = 0
	d[-2] = 0
	for el in s:
		if el == 'L':
			d[1] += 1
		elif el == 'R':
			d[-1] += 1
		elif el == 'U':
			d[2] += 1
		else:
			d[-2] += 1
	orizz = min(d[1], d[-1])
	vert = min(d[2], d[-2])
	if vert == 0 and orizz == 0:
		res = ''
	elif vert == 0:
		res = 'LR'
	elif orizz == 0:
		res = 'UD'
	else:
		res = 'U' * vert + 'L' * orizz + 'D' * vert + 'R' * orizz
	print(len(res))
	if len(res) > 0:
		print(res)


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()


import time
import string
LOCAL = False
start_time = None
if LOCAL:
	start_time = time.time()
q = int(input())
while q > 0:
	q -= 1
	instr = input()
	le = 0
	r = 0
	d = 0
	u = 0
	for i in instr:
		if i == 'R':
			r += 1
		elif i == 'L':
			le += 1
		elif i == 'U':
			u += 1
		elif i == 'D':
			d += 1
	a = min(le, r)
	b = min(u, d)
	if a != 0 and b == 0:
		a = 1
	elif b != 0 and a == 0:
		b = 1
	ri = a * 'R' + b * 'D' + a * 'L' + b * 'U'
	print(a * 2 + b * 2)
	print(ri)
if LOCAL:
	print('--- %s seconds ---' % (time.time() - start_time))


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


q = int(input())
cases = []
for _ in range(q):
	case = input()
	cases.append(case)

def solver(case):
	L = 0
	R = 0
	U = 0
	D = 0
	for i in case:
		if i == 'L':
			L += 1
		elif i == 'R':
			R += 1
		elif i == 'U':
			U += 1
		else:
			D += 1
	if L < R:
		R = L
	elif R < L:
		L = R
	if U < D:
		D = U
	elif D < U:
		U = D
	if L == 0 and U == 0:
		return (0, '')
	elif L == 0 and U != 0:
		return (2, 'UD')
	elif L != 0 and U == 0:
		return (2, 'LR')
	else:
		ret = ''
		ret += 'U' * U
		ret += 'R' * R
		ret += 'D' * D
		ret += 'L' * L
		return (len(ret), ret)
for case in cases:
	(n, ins) = solver(case)
	print(n)
	print(ins)


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)


from collections import Counter
for _ in range(int(input())):
	dic = Counter(input())
	rev = {'L': 'R', 'U': 'D', 'R': 'L', 'D': 'U'}
	l = min(dic['L'], dic['R'])
	u = min(dic['U'], dic['D'])
	if u and l:
		print(l * 2 + u * 2)
		print('L' * l + 'U' * u + 'R' * l + 'D' * u)
	elif u:
		print(2)
		print('UD')
	elif l:
		print(2)
		print('RL')
	else:
		print(0)


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 _ in range(int(input())):
	s = str(input())
	r = 0
	l = 0
	u = 0
	d = 0
	for i in s:
		if i == 'R':
			r += 1
		elif i == 'L':
			l += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	rlf = min(r, l)
	udf = min(u, d)
	if rlf == 0 and udf == 0:
		print(0)
	elif rlf == 0 and udf != 0:
		print(2)
		print('UD')
	elif rlf != 0 and udf == 0:
		print(2)
		print('RL')
	else:
		print(2 * rlf + 2 * udf)
		for i in range(rlf):
			print('R', end='')
		for i in range(udf):
			print('U', end='')
		for i in range(rlf):
			print('L', end='')
		for i in range(udf):
			print('D', end='')
		print()


n = int(input())
for j in range(n):
	L = 0
	R = 0
	U = 0
	D = 0
	string = str(input())
	for i in range(len(string)):
		if string[i] == 'L':
			L = L + 1
		elif string[i] == 'R':
			R = R + 1
		elif string[i] == 'U':
			U = U + 1
		elif string[i] == 'D':
			D = D + 1
	M = min(L, R)
	m = min(U, D)
	if D != U:
		D = m
		U = m
	if R != L:
		R = M
		L = M
	if m == 0 and M != 1 or (M == 0 and m != 1):
		if m == 0 and M == 0:
			print('0')
			print('')
		elif m == 0:
			print('2')
			print('LR')
		elif M == 0:
			print('2')
			print('UD')
	else:
		print(2 * R + 2 * U)
		print('U' * U + 'R' * R + 'D' * D + 'L' * L)


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


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)


t = int(input())
for i in range(t):
	a = input()
	d = [0, 0, 0, 0]
	for i in range(len(a)):
		if a[i] == 'L':
			d[0] += 1
		elif a[i] == 'R':
			d[1] += 1
		elif a[i] == 'U':
			d[2] += 1
		else:
			d[3] += 1
	d[1] = min(d[0], d[1])
	d[0] = min(d[0], d[1])
	d[2] = min(d[2], d[3])
	d[3] = min(d[2], d[3])
	if d[2] == 0 and d[0] != 0:
		d[0] = 1
		d[1] = 1
	elif d[0] == 0 and d[2] != 0:
		d[2] = 1
		d[3] = 1
	print(sum(d))
	print('L' * d[0] + 'D' * d[3] + 'R' * d[1] + 'U' * d[2])


from collections import Counter

def main():

	def solve():
		seq = list(input())
		sc = Counter(seq)
		lc = sc['L']
		rc = sc['R']
		uc = sc['U']
		dc = sc['D']
		hc = min(lc, rc)
		vc = min(uc, dc)
		if hc == 0 and vc == 0:
			print(0)
			return
		if hc == 0:
			print(2)
			print('UD')
			return
		if vc == 0:
			print(2)
			print('RL')
			return
		print(2 * (hc + vc))
		print('R' * hc + 'U' * vc + 'L' * hc + 'D' * vc)
	q = int(input())
	for _ in range(q):
		solve()
main()


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)


for _ in range(int(input())):
	s = input()
	new = ''
	d = {}
	d['L'] = s.count('L')
	d['U'] = s.count('U')
	d['R'] = s.count('R')
	d['D'] = s.count('D')
	d['L'] = d['R'] = min(d['L'], d['R'])
	d['U'] = d['D'] = min(d['U'], d['D'])
	if d['L'] == 0:
		del d['L']
	if d['R'] == 0:
		del d['R']
	if d['U'] == 0:
		del d['U']
	if d['D'] == 0:
		del d['D']
	ans = []
	if d == {}:
		ans = []
	elif len(d) == 2:
		for key in d:
			ans.append(key)
	else:
		ans.append('D' * d['D'])
		ans.append('R' * d['R'])
		ans.append('U' * d['U'])
		ans.append('L' * d['L'])
	if ans:
		s = ''.join(ans)
		print(len(s))
		print(s)
	else:
		print(0)
		print()


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)


q = int(input())
for i in range(q):
	s = input()
	cntL = cntR = cntU = cntD = 0
	for c in s:
		if c == 'L':
			cntL += 1
		elif c == 'R':
			cntR += 1
		elif c == 'U':
			cntU += 1
		elif c == 'D':
			cntD += 1
	mX = min(cntL, cntR)
	mY = min(cntU, cntD)
	if mX == 0 and mY != 0:
		print(2)
		print('DU')
	elif mX != 0 and mY == 0:
		print(2)
		print('LR')
	elif mX == 0 and mY == 0:
		print(0)
		print()
	else:
		print((mX + mY) * 2)
		print('R' * mX + 'D' * mY + 'L' * mX + 'U' * mY)


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)


def task(s):
	u = s.count('U')
	d = s.count('D')
	r = s.count('R')
	l = s.count('L')
	min_v = min(u, d)
	min_h = min(l, r)
	if min_v == 0 and min_h == 0:
		print(0)
		print()
	elif min_v == 0 and min_h != 0:
		print(2)
		print('LR')
	elif min_v != 0 and min_h == 0:
		print(2)
		print('UD')
	else:
		s2 = 'U' * min_v + 'R' * min_h + 'D' * min_v + 'L' * min_h
		print(len(s2))
		print(s2)
for i in range(int(input())):
	task(input())


q = int(input())
for i in range(q):
	s = input()
	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)
	res = ''
	if u == 0:
		if l >= 1:
			res += 'LR'
	elif l == 0:
		res += 'UD'
	else:
		res = l * 'R' + u * 'D' + l * 'L' + u * 'U'
	print(len(res))
	print(res)


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 _ in range(int(input())):
	s = input()
	a = s.count('U')
	b = s.count('D')
	c = s.count('L')
	d = s.count('R')
	co = 0
	if (a == 0 or b == 0) and (c != 0 and d != 0):
		print(2)
		print('LR')
	elif (c == 0 or d == 0) and (a != 0 and b != 0):
		print(2)
		print('UD')
	else:
		co += min(a, b)
		co += min(c, d)
		print(2 * co)
		for i in range(min(a, b)):
			print('U', end='')
		for i in range(min(c, d)):
			print('R', end='')
		for i in range(min(a, b)):
			print('D', end='')
		for i in range(min(c, d)):
			print('L', end='')
		print()


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


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


n = int(input())
l = []
for i in range(n):
	v = []
	x = input()
	(a, b, c, d) = (0, 0, 0, 0)
	for j in x:
		if j == 'U':
			a += 1
		elif j == 'D':
			b += 1
		elif j == 'R':
			c += 1
		elif j == 'L':
			d += 1
	if min(a, b) != 0 and min(c, d) != 0:
		for m in range(min(a, b)):
			v.append('U')
		for m in range(min(c, d)):
			v.append('R')
		for m in range(min(a, b)):
			v.append('D')
		for m in range(min(c, d)):
			v.append('L')
	elif min(a, b) == 0 and min(c, d) != 0:
		v.append('RL')
	elif min(c, d) == 0 and min(a, b) != 0:
		v.append('UD')
	else:
		v.append('0')
	v = ''.join(v)
	l.append(v)
for k in l:
	if k == '0':
		print(0)
		print()
	else:
		print(len(k))
		print(k)


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)


import sys
T = int(sys.stdin.readline())
d = {'L': 0, 'R': 1, 'D': 3, 'U': 2}
for _ in range(T):
	s = sys.stdin.readline().strip()
	count = [0, 0, 0, 0]
	for l in s:
		count[d[l]] += 1
	lr = min(count[0], count[1])
	ud = min(count[2], count[3])
	if lr == 0 or ud == 0:
		lr = min(1, lr)
		ud = min(1, ud)
	print((lr + ud) * 2)
	print('R' * lr + 'U' * ud + 'L' * lr + 'D' * ud)


for i in range(int(input())):
	t = input()
	f = {'L': 0, 'U': 0, 'R': 0, 'D': 0}
	for j in t:
		f[j] += 1
	row = min(f['U'], f['D'])
	col = min(f['L'], f['R'])
	a = min(f.values())
	if col > 0 and row > 0:
		u = ''
		u += 'L' * col
		u += 'U' * row
		u += 'R' * col
		u += 'D' * row
		print(len(u))
		print(u)
	elif col > 0 and row == 0:
		print(2)
		print('RL')
	elif row > 0 and col == 0:
		print(2)
		print('UD')
	else:
		print(0)


n = int(input())
for _ in range(n):
	D = {}
	D['U'] = 0
	D['D'] = 0
	D['L'] = 0
	D['R'] = 0
	s = input()
	for i in s:
		D[i] += 1
	x = min(D['L'], D['R'])
	y = min(D['U'], D['D'])
	if x > 1 and y == 0:
		print(2)
		print('RL')
	elif y > 1 and x == 0:
		print(2)
		print('UD')
	else:
		print(2 * x + 2 * y)
		for i in range(x):
			print('R', end='')
		for i in range(y):
			print('U', end='')
		for i in range(x):
			print('L', end='')
		for i in range(y):
			print('D', end='')
		print()


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)


t = int(input())
for i in range(t):
	a = input().strip()
	x = [0 for _ in range(4)]
	s = ''
	for i in a:
		if i == 'L':
			x[0] += 1
		elif i == 'R':
			x[1] += 1
		elif i == 'D':
			x[2] += 1
		elif i == 'U':
			x[3] += 1
	f = min(x[0], x[1])
	g = min(x[2], x[3])
	if f == 0:
		if x[2] > 0 and x[3] > 0:
			print(2)
			print('UD')
		else:
			print(0)
			print(s)
	elif g == 0:
		if x[0] > 0 and x[1] > 0:
			print(2)
			print('LR')
		else:
			print(0)
			print(s)
	else:
		print(2 * f + 2 * g)
		for j in range(f):
			s += 'R'
		for j in range(g):
			s += 'U'
		for j in range(f):
			s += 'L'
		for j in range(g):
			s += 'D'
		print(s)


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


t = int(input())
for i in range(t):
	s = input()
	a = min(s.count('L'), s.count('R'))
	b = a
	c = min(s.count('U'), s.count('D'))
	d = c
	if a == 0 and c != 0:
		s = 'UD'
	elif c == 0 and a != 0:
		s = 'RL'
	else:
		s = 'R' * a + 'D' * c + 'L' * a + 'U' * c
	print(len(s))
	print(s)


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)


for i in range(int(input())):
	s = input()
	lcnt = 0
	rcnt = 0
	ucnt = 0
	dcnt = 0
	for i in range(len(s)):
		if s[i] == 'L':
			lcnt += 1
		if s[i] == 'R':
			rcnt += 1
		if s[i] == 'U':
			ucnt += 1
		if s[i] == 'D':
			dcnt += 1
	tmp = min(lcnt, rcnt)
	tmp1 = min(dcnt, ucnt)
	if tmp == 0 or tmp1 == 0:
		if lcnt > 0 and rcnt > 0:
			print(2)
			print('LR')
		elif ucnt > 0 and dcnt > 0:
			print(2)
			print('UD')
		else:
			print(0)
	else:
		print(tmp * 2 + tmp1 * 2)
		s1 = str()
		s1 += tmp1 * 'U'
		s1 += tmp * 'R'
		s1 += tmp1 * 'D'
		s1 += tmp * 'L'
		print(s1)


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:
		l = r
	elif r > l:
		r = l
	if u > d:
		u = d
	elif d > u:
		d = u
	if l == 0 and r == 0 and (d == 0) and (r == 0):
		print(0)
		print(' ')
	elif l == 0 and r == 0:
		print(2)
		print('UD')
	elif d == 0 and u == 0:
		print(2)
		print('RL')
	else:
		ans = l + r + u + d
		ans2 = u * 'U' + r * 'R' + d * 'D' + l * 'L'
		print(ans)
		print(ans2)


q = int(input())
for i in range(q):
	s = input()
	d = {'L': 0, 'D': 0, 'R': 0, 'U': 0}
	for i in s:
		d[i] = d.get(i, 0) + 1
	tc1 = min(d['L'], d['R'])
	tc2 = min(d['D'], d['U'])
	if tc1 == 0 and tc2 == 0:
		print(0)
	elif tc1 != 0 and tc2 != 0:
		a = ['L', 'D', 'R', 'U']
		print(tc1 * 2 + tc2 * 2)
		ans = ''
		for qq in range(len(a)):
			j = a[qq]
			if j in 'LR':
				ans += j * tc1
			else:
				ans += j * tc2
		print(ans)
	else:
		print(2)
		if tc1 == 0:
			print('DU')
		else:
			print('LR')


import sys
r_input = sys.stdin.readline
q = int(r_input())
for _ in range(q):
	s = r_input().rstrip()
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	result = ''
	save1 = min(l, r)
	save2 = min(u, d)
	if not save1 and (not save2):
		print(0)
	elif not save1:
		print(2)
		print('UD')
	elif not save2:
		print(2)
		print('LR')
	else:
		print((save1 + save2) * 2)
		print('U' * save2 + 'R' * save1 + 'D' * save2 + 'L' * save1)


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)


q = int(input())
ups = 0
downs = 0
lefts = 0
rights = 0
for i in range(q):
	s = input()
	for i in range(len(s)):
		if s[i] == 'U':
			ups += 1
		if s[i] == 'D':
			downs += 1
		if s[i] == 'L':
			lefts += 1
		if s[i] == 'R':
			rights += 1
	min1 = min(ups, downs)
	min2 = min(lefts, rights)
	if min1 == 0:
		if min2 == 0:
			print('0')
			print()
		if min2 != 0:
			print('2')
			print('LR')
	elif min2 == 0:
		print('2')
		print('UD')
	else:
		print(2 * (min1 + min2))
		print('L' * min2 + 'D' * min1 + 'R' * min2 + 'U' * min1)
	ups = 0
	downs = 0
	lefts = 0
	rights = 0


from sys import stdin
for _ in range(int(stdin.readline())):
	path = stdin.readline().strip('\n')
	countU = path.count('U')
	countD = path.count('D')
	countR = path.count('R')
	countL = path.count('L')
	mUD = min(countU, countD)
	mRL = min(countR, countL)
	if mUD == 0 and mRL == 0:
		print('0')
		print()
		continue
	if mUD == 0:
		print('2')
		print('LR')
		continue
	if mRL == 0:
		print('2')
		print('UD')
		continue
	(countU, countD) = (mUD, mUD)
	(countR, countL) = (mRL, mRL)
	print(countR + countL + countU + countD)
	print('R' * countR, end='')
	print('U' * countU, end='')
	print('L' * countL, end='')
	print('D' * countD)


t = int(input())
all_res = []
for _ in range(t):
	(x, y) = (0, 0)
	(cntL, cntR, cntU, cntD) = (0, 0, 0, 0)
	s = input()
	for i in s:
		if i == 'U':
			y += 1
			cntU += 1
		if i == 'D':
			y -= 1
			cntD += 1
		if i == 'L':
			x -= 1
			cntL += 1
		if i == 'R':
			x += 1
			cntR += 1
	rmvU = 0 if y <= 0 else y
	rmvD = 0 if y >= 0 else abs(y)
	rmvL = 0 if x >= 0 else abs(x)
	rmvR = 0 if x <= 0 else x
	res = 'R' * (cntR - rmvR) + 'D' * (cntD - rmvD) + 'L' * (cntL - rmvL) + 'U' * (cntU - rmvU)
	if len(res) and res.count('L') == res.count('R') == 0:
		res = 'UD'
	if len(res) and res.count('U') == res.count('D') == 0:
		res = 'LR'
	all_res.append(str(len(res)))
	all_res.append(res)
print('\n'.join(all_res))


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


def solve():
	n = int(input())
	for _ in range(n):
		seq = input()
		(R, L, U, D) = (0, 0, 0, 0)
		for char in seq:
			if char == 'R':
				R += 1
			elif char == 'L':
				L += 1
			elif char == 'U':
				U += 1
			else:
				D += 1
		if R == L == U == D == 0:
			print(len(seq))
			print(seq)
			break
		R = R - max(R - L, 0)
		L = L - max(L - R, 0)
		U = U - max(U - D, 0)
		D = D - max(D - U, 0)
		if R == L == U == D == 0:
			print('0')
		elif U == D == 0:
			print('2')
			print('RL')
		elif R == L == 0:
			print('2')
			print('UD')
		else:
			x = ''.join(['R' * R, 'D' * D, 'L' * L, 'U' * U])
			print(len(x))
			print(x)
solve()


t = int(input())
while t > 0:
	s = input()
	f = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for x in s:
		f[x] += 1
	hor = min(f['L'], f['R'])
	ver = min(f['U'], f['D'])
	tot = 2 * hor + 2 * ver
	if ver == 0 and hor == 0:
		print(0)
	elif ver == 0:
		print(2)
		print('LR')
	elif hor == 0:
		print(2)
		print('UD')
	else:
		print(tot)
		print('R' * hor + 'U' * ver + 'L' * hor + 'D' * ver)
	t -= 1


q = int(input())
for _ in range(q):
	a = input()
	lc = min(a.count('L'), a.count('R')) * 2
	dc = min(a.count('D'), a.count('U')) * 2
	tc = lc if dc == 0 else dc if lc == 0 else dc + lc
	if not tc:
		print(0)
		print('')
	elif lc and dc:
		print(tc)
		print('U' * (int(dc) // 2) + 'R' * (int(lc) // 2) + 'D' * (int(dc) // 2) + 'L' * (int(lc) // 2))
	elif lc:
		print(2)
		print('LR')
	elif dc:
		print(2)
		print('UD')


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)


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


q = int(input())
for i in range(q):
	a = input()
	b = len(a)
	(l, u, r, d) = (0, 0, 0, 0)
	for j in range(b):
		if a[j] == 'L':
			l = l + 1
		elif a[j] == 'R':
			r = r + 1
		elif a[j] == 'D':
			d = d + 1
		elif a[j] == 'U':
			u = u + 1
	s1 = min(l, r)
	s2 = min(d, u)
	x = ''
	if s1 == 0 and s2 >= 1:
		print(2)
		print('UD')
	elif s2 == 0 and s1 >= 1:
		print(2)
		print('RL')
	elif s1 == 0 and s2 == 0:
		print(0)
		print(' ')
	else:
		y = 2 * (s1 + s2)
		print(y)
		x = 'D' * s2 + 'L' * s1 + 'U' * s2 + 'R' * s1
		print(x)


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()


t = int(input())
for i in range(t):
	s = input()
	(u, d, r, l) = (0, 0, 0, 0)
	for i in s:
		if i == 'U':
			u += 1
		elif i == 'D':
			d += 1
		elif i == 'R':
			r += 1
		else:
			l += 1
	s = ''
	h = min(l, r)
	v = min(u, d)
	if h != 0 and v != 0:
		s += 'R' * h
		s += 'U' * v
		s += 'L' * h
		s += 'D' * v
	if min(h, v) == 0:
		if v == 0:
			h = min(h, 1)
			s += 'L' * h + 'R' * h
		else:
			v = min(v, 1)
			s += 'U' * v + 'D' * v
	print(len(s))
	print(s)


def solve(l, d, ans):
	if d == 0:
		if l > 0:
			s = 'RL'
			ans.append(2)
			ans.append(s)
			return
		ans.append(0)
		ans.append('')
		return
	if l == 0:
		if d > 0:
			s = 'UD'
			ans.append(2)
			ans.append(s)
			return
		ans.append(0)
		ans.append('')
		return
	s = ''
	for i in range(l):
		s += 'R'
	for i in range(d):
		s += 'D'
	for i in range(l):
		s += 'L'
	for i in range(d):
		s += 'U'
	ans.append(len(s))
	ans.append(s)

def main():
	ans = []
	q = int(input())
	for i in range(q):
		s = input()
		l = s.count('L')
		r = s.count('R')
		u = s.count('U')
		d = s.count('D')
		l_req = min(l, r)
		d_req = min(u, d)
		solve(l_req, d_req, ans)
	for i in ans:
		print(i)
main()


from collections import Counter

def solve(s):
	count = Counter(s)
	height = min(count['U'], count['D'])
	width = min(count['L'], count['R'])
	if height == 0:
		if width > 0:
			return (2, 'LR')
		return (0, '')
	if width == 0:
		if height > 0:
			return (2, 'UD')
		return (0, '')
	size = 2 * (height + width)
	path = 'U' * height + 'R' * width + 'D' * height + 'L' * width
	return (size, path)
for _ in range(int(input())):
	s = input()
	(size, path) = solve(s)
	print(size)
	print(path)


from fractions import gcd
from heapq import *
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7

def main():
	q = int(input())
	for i in range(q):
		s = input()
		d = defaultdict(int)
		se = set()
		for i in range(len(s)):
			d[s[i]] += 1
			se.add(s[i])
		if len(list(se)) == 1:
			print(0)
			print('')
			continue
		elif s.count('L') + s.count('R') == len(s):
			print(2)
			print('LR')
			continue
		elif s.count('U') + s.count('D') == len(s):
			print(2)
			print('UD')
			continue
		ans = float('inf')
		ansl = []
		for i in ['L', 'R']:
			ans = min(ans, d[i])
		tans = ans
		ans = float('inf')
		for i in ['U', 'D']:
			ans = min(ans, d[i])
		if ans == 0 and tans > 0:
			print(2)
			print('LR')
			continue
		elif ans > 0 and tans == 0:
			print(2)
			print('UD')
		else:
			ansl += ['L'] * tans
			ansl += ['U'] * ans
			ansl += ['R'] * tans
			ansl += ['D'] * ans
			print(len(ansl))
			print(''.join(map(str, ansl)))
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)


q = int(input())
for i in range(q):
	s = input()
	du = min(s.count('D'), s.count('U'))
	lr = min(s.count('L'), s.count('R'))
	if du != 0 and lr != 0:
		print(2 * du + 2 * lr)
		print('D' * du + 'L' * lr + 'U' * du + 'R' * lr)
	elif du == 0:
		if s.count('L') != 0 and s.count('R') != 0:
			print(2)
			print('LR')
		else:
			print(0)
	elif lr == 0:
		if s.count('D') != 0 and s.count('U') != 0:
			print(2)
			print('DU')
		else:
			print(0)


for _ in range(int(input())):
	arr = str(sorted(input()))
	u = arr.count('U')
	d = arr.count('D')
	r = arr.count('R')
	l = arr.count('L')
	u = min(u, d)
	d = u
	r = min(r, l)
	l = r
	if u == 0 and r == 0:
		print(0)
		continue
	elif u == 0:
		print(2)
		print('LR')
	elif l == 0:
		print(2)
		print('UD')
	else:
		print(u * 2 + l * 2)
		print(''.join(u * ['U'] + l * ['L'] + d * ['D'] + r * ['R']))


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 range(int(input())):
	s = list(input())
	(l, r, u, d) = [s.count(i) for i in 'LRUD']
	lr = min(l, r)
	ud = min(u, d)
	coun = ''
	if lr == ud == 0:
		coun = ''
	elif lr == 0:
		coun = 'UD'
	elif ud == 0:
		coun = 'LR'
	else:
		coun = 'U' * ud + 'L' * lr + 'D' * ud + 'R' * lr
	print(len(coun))
	print(coun)


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)


from collections import deque

def solve(arr):
	dict = {'R': 0, 'L': 0, 'U': 0, 'D': 0}
	for char in arr:
		dict[char] += 1
	dict['R'] = min(dict['R'], dict['L'])
	dict['L'] = min(dict['R'], dict['L'])
	dict['U'] = min(dict['U'], dict['D'])
	dict['D'] = min(dict['U'], dict['D'])
	if dict['U'] == 0:
		dict['R'] = min(dict['R'], 1)
		dict['L'] = dict['R']
	if dict['R'] == 0:
		dict['U'] = min(dict['U'], 1)
		dict['D'] = dict['U']
	result = 'R' * dict['R'] + 'U' * dict['U'] + 'L' * dict['L'] + 'D' * dict['D']
	return str(len(result)) + '\n' + result + '\n'
line = input().split(' ')
output = ''
for i in range(int(line[0])):
	arr = input()
	output += solve(arr)
print(output)


import sys
import math
import itertools
import collections

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

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
q = ii()
for _ in range(q):
	s = input()
	(r, u, l, d) = (s.count('R'), s.count('U'), s.count('L'), s.count('D'))
	if min(r, l) == 0 and min(u, d) != 0:
		print(2)
		print('UD')
	elif min(u, d) == 0 and min(r, l) != 0:
		print(2)
		print('RL')
	else:
		print(2 * (min(u, d) + min(r, l)))
		print('R' * min(r, l) + 'U' * min(u, d) + 'L' * min(r, l) + 'D' * min(u, d))


from collections import defaultdict
inst = {'U': [0, 1], 'D': [0, -1], 'R': [1, 0], 'L': [-1, 0]}
q = int(input())
while q > 0:
	q -= 1
	s = input().strip()
	dic = defaultdict(int)
	sub = [0, 0]
	for i in range(len(s)):
		sub[0] += inst[s[i]][0]
		sub[1] += inst[s[i]][1]
		dic[s[i]] += 1
	while sub[0] != 0:
		if sub[0] > 0:
			if dic['R'] > 0:
				sub[0] -= 1
				dic['R'] -= 1
			else:
				break
		if sub[0] < 0:
			if dic['L'] > 0:
				sub[0] += 1
				dic['L'] -= 1
			else:
				break
	while sub[1] != 0:
		if sub[1] > 0:
			if dic['U'] > 0:
				sub[1] -= 1
				dic['U'] -= 1
			else:
				break
		if sub[1] < 0:
			if dic['D'] > 0:
				sub[1] += 1
				dic['D'] -= 1
			else:
				break
	if sub != [0, 0]:
		print(0)
		print()
		continue
	res = ''
	if dic['D'] == 0 and dic['U'] == 0:
		if dic['L'] != 0 and dic['R'] != 0:
			print(2)
			print('LR')
		else:
			print(0)
			print()
		continue
	if dic['L'] == 0 and dic['R'] == 0:
		if dic['U'] != 0 and dic['D'] != 0:
			print(2)
			print('UD')
		else:
			print(0)
			print()
		continue
	while dic['D'] != 0:
		res += 'D'
		dic['D'] -= 1
	while dic['L'] != 0:
		res += 'L'
		dic['L'] -= 1
	while dic['U'] != 0:
		res += 'U'
		dic['U'] -= 1
	while dic['R'] != 0:
		res += 'R'
		dic['R'] -= 1
	print(len(res))
	print(res)


from sys import stdin
r = stdin.readline

def main():
	cases = int(r())
	for case in range(cases):
		comm = r().strip()
		count = {'D': 0, 'U': 0, 'R': 0, 'L': 0}
		for com in comm:
			count[com] += 1
		inst = ''
		(up, down, right, left) = (count['U'], count['D'], count['R'], count['L'])
		if down >= 1 and up >= 1 and (right >= 1) and (left >= 1):
			if up < down:
				inst += 'U' * up
				if left < right:
					inst += 'L' * left
					inst += 'D' * up
					inst += 'R' * left
				else:
					inst += 'R' * right
					inst += 'D' * up
					inst += 'L' * right
			else:
				inst += 'D' * down
				if left < right:
					inst += 'L' * left
					inst += 'U' * down
					inst += 'R' * left
				else:
					inst += 'R' * right
					inst += 'U' * down
					inst += 'L' * right
		elif left >= 1 and right >= 1:
			inst = 'LR'
		elif up >= 1 and down >= 1:
			inst = 'UD'
		print(len(inst))
		print(inst)
main()


q = int(input())
for i in range(q):
	s = input()
	ans = ''
	xp = 0
	xn = 0
	yp = 0
	yn = 0
	for i in s:
		if i == 'L':
			xn += 1
		elif i == 'R':
			xp += 1
		elif i == 'U':
			yp += 1
		elif i == 'D':
			yn += 1
	x = 0
	y = 0
	if abs(xp - xn) != 0:
		x = min(xp, xn)
		xp = x
		xn = x
	else:
		x = xp
	if abs(yp - yn) != 0:
		y = min(yp, yn)
		yp = y
		yn = y
	else:
		y = yp
	if y == 0:
		if x > 1:
			xp = 1
			xn = 1
			x = 1
	if x == 0:
		if y > 1:
			yp = 1
			yn = 1
			y = 1
	if x > 0 and y > 0:
		ans += 'R' * x
		ans += 'U' * y
		ans += 'L' * x
		ans += 'D' * y
	if x > 0 and y == 0:
		ans += 'LR'
	if y > 0 and x == 0:
		ans += 'UD'
	print(len(ans))
	print(ans)


a = int(input())
for i in range(a):
	b = input()
	l = [0, 0, 0, 0]
	for i in b:
		if i == 'U':
			l[0] += 1
		elif i == 'D':
			l[1] += 1
		elif i == 'R':
			l[2] += 1
		else:
			l[3] += 1
	ans1 = min(l[0], l[1])
	ans2 = min(l[2], l[3])
	if ans1 != 0 and ans2 != 0:
		print(2 * ans1 + 2 * ans2)
		k = 'U' * ans1 + 'R' * ans2 + 'D' * ans1 + 'L' * ans2
		print(k)
	elif ans2 > 0:
		print(2)
		print('RL')
	elif ans1 > 0:
		print(2)
		print('UD')
	else:
		print(0)


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()


n = int(input())
for i in range(n):
	s = input()
	L = list(s)
	nU = nD = nL = nR = 0
	for c in L:
		if c == 'U':
			nU += 1
		elif c == 'D':
			nD += 1
		elif c == 'R':
			nR += 1
		else:
			nL += 1
	if nD != nU:
		nD = nU = min(nD, nU)
	if nL != nR:
		nL = nR = min(nL, nR)
	if nU == 0 and nD == 0 and (nL == 0) and (nR == 0):
		print('0')
	elif nU != 0 and nD != 0 and (nL == 0) and (nR == 0):
		print('2')
		print('UD')
	elif nL != 0 and nR != 0 and (nU == 0) and (nD == 0):
		print('2')
		print('LR')
	else:
		print(nU + nD + nL + nR)
		print(nR * 'R' + nU * 'U' + nL * 'L' + nD * 'D')


q = int(input())
for _ in range(q):
	s = input()
	vtc = min(s.count('U'), s.count('D'))
	hrz = min(s.count('L'), s.count('R'))
	if (vtc, hrz).count(0) == 1:
		print(2)
		print('LR' if vtc == 0 else 'UD')
	else:
		print((vtc + hrz) * 2)
		print('U' * vtc + 'L' * hrz + 'D' * vtc + 'R' * hrz)


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)


q = int(input())
while q:
	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
	L = min(L, R)
	R = min(L, R)
	U = min(U, D)
	D = min(U, D)
	if U == 0 and L == 0:
		print(0)
		print()
	elif U == 0:
		print(2)
		print('LR')
	elif L == 0:
		print(2)
		print('UD')
	else:
		print(L + R + U + D)
		print('R' * R + 'U' * U + 'L' * L + 'D' * D)
	q -= 1


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')


for _ in range(int(input())):
	s = input()
	(L, R, U, D) = (0, 0, 0, 0)
	for char in s:
		if char == 'L':
			L += 1
		elif char == 'D':
			D += 1
		elif char == 'U':
			U += 1
		else:
			R += 1
	ans = ''
	if min(L, R) == 0:
		if min(U, D) >= 1:
			ans = 'UD'
	elif min(U, D) == 0:
		if min(L, R) >= 1:
			ans = 'LR'
	else:
		ans = 'R' * min(L, R) + 'U' * min(U, D) + 'L' * min(L, R) + 'D' * min(U, D)
	print(len(ans))
	print(ans)


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


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


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()


Q = int(input())
for q in range(0, Q):
	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
		else:
			d += 1
	l = min(l, r)
	r = l
	u = min(u, d)
	d = u
	ns = ''
	if r != 0 and u == 0:
		print(2)
		print('LR')
	elif r == 0 and u != 0:
		print(2)
		print('UD')
	else:
		for i in range(0, r):
			ns += 'R'
		for i in range(0, u):
			ns += 'U'
		for i in range(0, l):
			ns += 'L'
		for i in range(0, d):
			ns += 'D'
		print(l + r + u + d)
		print(ns)


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


from math import *
import os, sys
from io import BytesIO
for i in range(int(input())):
	s = input()
	d = {}
	d['L'] = 0
	d['R'] = 0
	d['U'] = 0
	d['D'] = 0
	for c in s:
		d[c] += 1
	if d['U'] == 0 or d['D'] == 0:
		d['U'] = 0
		d['D'] = 0
	if d['R'] == 0 or d['L'] == 0:
		d['R'] = 0
		d['L'] = 0
	if d['R'] == 0 or d['L'] == 0:
		if d['U'] != 0 and d['D'] != 0:
			print(2)
			print('UD')
			continue
		else:
			print(0)
			continue
	if d['U'] == 0 or d['D'] == 0:
		if d['L'] != 0 and d['R'] != 0:
			print(2)
			print('LR')
			continue
		else:
			print(0)
			continue
	else:
		x = min(d['U'], d['D'])
		y = min(d['L'], d['R'])
		print(2 * x + 2 * y)
		print('U' * x + 'L' * y + 'D' * x + 'R' * y)


t = int(input())
for _ in range(t):
	s = input()
	(r, l, d, u) = (0, 0, 0, 0)
	for i in s:
		if i == 'R':
			r += 1
		if i == 'L':
			l += 1
		if i == 'D':
			d += 1
		if i == 'U':
			u += 1
	a = min(u, d)
	b = min(r, l)
	if a == 0 and b != 0:
		print(2)
		print('RL')
		continue
	elif b == 0 and a != 0:
		print(2)
		print('DU')
		continue
	res = a * 'U' + b * 'R' + a * 'D' + b * 'L'
	print(len(res))
	print(res)


from collections import Counter
q = int(input())
for _ in range(q):
	cmd = input()
	freq = dict(Counter(cmd))
	for k in 'LRUD':
		if k not in freq:
			freq[k] = 0
	lr = min(freq['L'], freq['R'])
	ud = min(freq['U'], freq['D'])
	x = 1 if lr and (not ud) else lr
	y = 1 if ud and (not lr) else ud
	print(2 * (x + y))
	print('R' * x + 'U' * y + 'L' * x + 'D' * y)


import sys
input = sys.stdin.readline
q = int(input())
from collections import Counter
for test in range(q):
	S = input().strip()
	C = Counter(S)
	L = C['L']
	R = C['R']
	U = C['U']
	D = C['D']
	if U == 0 or D == 0:
		if L > 0 and R > 0:
			print(2)
			print('LR')
			continue
		else:
			print(0)
			continue
	elif L == 0 or R == 0:
		if U > 0 and D > 0:
			print(2)
			print('UD')
			continue
		else:
			print(0)
			continue
	else:
		MU = min(U, D)
		ML = min(L, R)
		ANS = 'U' * MU + 'R' * ML + 'D' * MU + 'L' * ML
		print(len(ANS))
		print(ANS)


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)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(l()[0]):
	s = input()
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	v = min(u, d)
	h = min(l, r)
	if h == 0 and v == 0:
		print(0)
		print('')
		continue
	if h == 0 and v > 1 or (v == 0 and h > 1):
		print(2)
		if v:
			print('UD')
		else:
			print('RL')
		continue
	print(2 * h + 2 * v)
	print('L' * h + 'U' * v + 'R' * h + 'D' * v)


num = int(input())
for i in range(num):
	order = input()
	r = order.count('R')
	l = order.count('L')
	u = order.count('U')
	d = order.count('D')
	rl = min(r, l)
	ud = min(u, d)
	if rl == 0 and ud == 0:
		print(0)
		print()
	elif rl == 0 or ud == 0:
		print(2)
		print('RL') if rl != 0 else print('UD')
	else:
		print((rl + ud) * 2)
		last_order = 'R' * rl + 'U' * ud + 'L' * rl + 'D' * ud
		print(last_order)


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)


q = int(input())
answers = []
for i in range(q):
	s = input()
	R = [c for c in s if c == 'R']
	L = [c for c in s if c == 'L']
	U = [c for c in s if c == 'U']
	D = [c for c in s if c == 'D']
	if len(U) == 0 or len(D) == 0:
		if len(R) > 0:
			R = ['R']
		if len(L) > 0:
			L = ['L']
	if len(R) == 0 or len(L) == 0:
		if len(U) > 0:
			U = ['U']
		if len(D) > 0:
			D = ['D']
	answer = ''
	for i in range(min(len(R), len(L))):
		answer += 'R'
	for i in range(min(len(U), len(D))):
		answer += 'U'
	for i in range(min(len(R), len(L))):
		answer += 'L'
	for i in range(min(len(U), len(D))):
		answer += 'D'
	answers.append([len(answer), answer])
for i in range(len(answers)):
	print(answers[i][0])
	print(answers[i][1])


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())):
	s = input()
	ats = ''
	if min(s.count('U'), s.count('D')) > 0 and min(s.count('L'), s.count('R')) > 0:
		ats += 'U' * min(s.count('U'), s.count('D'))
		ats += 'R' * min(s.count('L'), s.count('R'))
		ats += 'D' * min(s.count('U'), s.count('D'))
		ats += 'L' * min(s.count('L'), s.count('R'))
	elif min(s.count('U'), s.count('D')) == 0:
		ats += 'R' * min(s.count('L'), s.count('R'), 1)
		ats += 'L' * min(s.count('L'), s.count('R'), 1)
	elif min(s.count('L'), s.count('R')) == 0:
		ats += 'U' * min(s.count('U'), s.count('D'), 1)
		ats += 'D' * min(s.count('U'), s.count('D'), 1)
	print(len(ats))
	print(ats)


t = int(input())
while t:
	t -= 1
	s = input()
	n = len(s)
	d = 0
	u = 0
	r = 0
	l = 0
	for i in range(n):
		if s[i] == 'R':
			r += 1
		if s[i] == 'L':
			l += 1
		if s[i] == 'U':
			u += 1
		if s[i] == 'D':
			d += 1
	if min(r, l) == 0 and min(u, d) > 0:
		print(2)
		print('DU')
	elif min(u, d) == 0 and min(r, l) > 0:
		print(2)
		print('RL')
	elif min(r, l) == 0 and min(u, d) == 0:
		print(0)
		print()
	else:
		x = min(l, r)
		y = min(u, d)
		print(2 * x + 2 * y)
		print('U' * y + 'R' * x + 'D' * y + 'L' * x)


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')
q = int(input())
while q > 0:
	s = str(input())
	l = 0
	r = 0
	u = 0
	d = 0
	for le in s:
		if le == 'R':
			r += 1
		elif le == 'L':
			l += 1
		elif le == 'U':
			u += 1
		else:
			d += 1
	value1 = min(r, l)
	value2 = min(u, d)
	if value1 == 0 and value2 == 0:
		print(0)
		print()
	elif value1 == 0:
		print(2, '\n', 'UD', sep='')
	elif value2 == 0:
		print(2, '\n', 'RL', sep='')
	else:
		print(2 * value1 + 2 * value2)
		for i in range(value1):
			print('L', sep='', end='')
		for i in range(value2):
			print('U', sep='', end='')
		for i in range(value1):
			print('R', sep='', end='')
		for i in range(value2):
			print('D', sep='', end='')
		print()
	q -= 1


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')
for i in range(int(input())):
	string = input()
	(r, l, u, d) = (0, 0, 0, 0)
	for j in string:
		if j == 'R':
			r += 1
		elif j == 'L':
			l += 1
		elif j == 'U':
			u += 1
		elif j == 'D':
			d += 1
	h = min(r, l)
	v = min(u, d)
	if h == 0 or v == 0:
		if v == 0:
			h = min(h, 1)
			print(2 * h)
			print('R' * h + 'L' * h)
		else:
			v = min(v, 1)
			print(2 * v)
			print('U' * v + 'D' * v)
	else:
		ans = ''
		ans += 'R' * h
		ans += 'U' * v
		ans += 'L' * h
		ans += 'D' * v
		print(2 * h + 2 * v)
		print(ans)


q = int(input())
for _ in range(q):
	s = input()
	if s == '':
		print(0)
		print()
		continue
	aa = min(s.count('U'), s.count('D'))
	bb = min(s.count('L'), s.count('R'))
	if bb == 0 and aa == 0:
		print(0)
		print()
		continue
	elif aa == 0:
		print(2)
		print('RL')
		continue
	elif bb == 0:
		print(2)
		print('DU')
		continue
	print(aa * 2 + bb * 2)
	print('D' * aa + 'R' * bb + 'U' * aa + 'L' * bb)


def end_correcter(movt):
	sum_x = 0
	sum_y = 0
	remover_x = [(0, 0), (1, 0), (-1, 0)]
	remover_y = [(0, 0), (0, 1), (0, -1)]
	for i in range(len(movt)):
		sum_x += movt[i][0]
		sum_y += movt[i][1]
	while sum_x != 0:
		if sum_x < 0:
			movt.remove((-1, 0))
			sum_x += 1
		else:
			movt.remove((1, 0))
			sum_x -= 1
	while sum_y != 0:
		if sum_y < 0:
			movt.remove((0, -1))
			sum_y += 1
		else:
			movt.remove((0, 1))
			sum_y -= 1
	return movt

def place_items(movt):
	count_U = min((movt.count('U'), movt.count('D')))
	count_R = min((movt.count('R'), movt.count('L')))
	if count_U == 0 and count_R == 0:
		return ''
	elif count_U == 0:
		return 'LR'
	elif count_R == 0:
		return 'UD'
	return 'U' * count_U + 'R' * count_R + 'D' * count_U + 'L' * count_R
rounds = int(input())
movt_dict = {'L': (-1, 0), 'R': (1, 0), 'U': (0, 1), 'D': (0, -1)}
movt_dict_reverse = {(-1, 0): 'L', (1, 0): 'R', (0, 1): 'U', (0, -1): 'D'}
for i in range(rounds):
	numbers = list(input())
	for i in range(len(numbers)):
		numbers[i] = movt_dict[numbers[i]]
	movt = end_correcter(numbers)
	answer = ''.join([movt_dict_reverse[i] for i in movt])
	real_answer = place_items(answer)
	print(len(real_answer))
	print(real_answer)


import collections as c
for tc in [0] * int(input()):
	s = list(input())
	d = s.copy()
	dd = c.Counter(s)
	a = [dd['U'], dd['D']]
	b = [dd['L'], dd['R']]
	x = min(a)
	y = min(b)
	if x == 0 and y >= 1:
		print(2)
		print('LR')
	elif x >= 1 and y == 0:
		print(2)
		print('UD')
	else:
		print(2 * x + 2 * y)
		print('U' * x + 'L' * y + 'D' * x + 'R' * y)


for _ in range(int(input())):
	A = list(input())
	sumx = 0
	sumy = 0
	posx = 0
	negx = 0
	posy = 0
	negy = 0
	for ele in A:
		if ele == 'U':
			posy += 1
			sumy += 1
		if ele == 'D':
			negy += 1
			sumy -= 1
		if ele == 'R':
			posx += 1
			sumx += 1
		if ele == 'L':
			negx += 1
			sumx -= 1
	if sumx > 0:
		posx = negx
		sumx = 0
	elif sumy < 0:
		negx = posx
		sumx = 0
	if sumy > 0:
		posy = negy
		sumy = 0
	elif sumy < 0:
		negy = posy
		sumy = 0
	l = (posx + posy) * 2
	if posx > 0 and posy > 0:
		print(l)
		for i in range(posx):
			print('R', end='')
		for j in range(posy):
			print('D', end='')
		for k in range(posx):
			print('L', end='')
		for p in range(posy):
			print('U', end='')
		print()
	elif posx == 0 and posy > 0:
		print(2)
		print('UD')
	elif posy == 0 and posx > 0:
		print(2)
		print('LR')
	else:
		print(0)


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()


from collections import *
for i in range(int(input())):
	(c, out) = (Counter(input()), '')
	if c['L'] == 0 or c['R'] == 0:
		if c['U'] > 0 and c['D'] > 0:
			(ans, out) = (2, 'UD')
		else:
			ans = 0
	elif c['U'] == 0 or c['D'] == 0:
		if c['L'] > 0 and c['R'] > 0:
			(ans, out) = (2, 'LR')
		else:
			ans = 0
	else:
		(mi1, mi2) = (min(c['U'], c['D']), min(c['L'], c['R']))
		(ans, out) = ((mi1 + mi2) * 2, out + mi1 * 'U' + mi2 * 'R' + mi1 * 'D' + mi2 * 'L')
	print(ans, out, sep='\n')


import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = pow(10, 9) + 7

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

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def rec(a, b, i):
	if a == b:
		return 0
	return min(rec(a + i, b, i + 1), rec(a, b + i, i + 1))

def solve():
	s = list(inp())
	lcnt = s.count('L')
	rcnt = s.count('R')
	mm = min(lcnt, rcnt)
	lcnt = mm
	rcnt = mm
	ucnt = s.count('U')
	dcnt = s.count('D')
	mm = min(ucnt, dcnt)
	ucnt = mm
	dcnt = mm
	ans = ''
	for i in range(0, ucnt):
		ans += 'U'
	for i in range(0, rcnt):
		ans += 'R'
	for i in range(0, dcnt):
		ans += 'D'
	for i in range(0, lcnt):
		ans += 'L'
	if lcnt > 1 and ucnt == 0:
		print(2)
		print('LR')
	elif ucnt > 1 and lcnt == 0:
		print(2)
		print('UD')
	elif len(ans) == 0:
		print(0)
	else:
		print(len(ans))
		print(ans)
testcase(int(inp()))


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	s = inp()
	u = s.count('U')
	d = s.count('D')
	r = s.count('R')
	l = s.count('L')
	(u, r) = (min(u, d), min(l, r))
	if u == 0 and r == 0:
		print(0)
	elif u == 0:
		print(2)
		print('LR')
	elif r == 0:
		print(2)
		print('UD')
	else:
		print(2 * (u + r))
		print('U' * u + 'R' * r + 'D' * u + 'L' * r)


for i in range(int(input())):
	x = input()
	l = x.count('L')
	r = x.count('R')
	u = x.count('U')
	d = x.count('D')
	q = min(l, r)
	w = min(u, d)
	final = []
	s = ''
	if q == 0 and w == 0:
		print(0)
	elif q == 0 and w > 0:
		print(2)
		print('UD')
	elif w == 0 and q > 0:
		print(2)
		print('LR')
	else:
		for i in range(q):
			final.append('R')
		for i in range(w):
			final.append('U')
		for i in range(q):
			final.append('L')
		for i in range(w):
			final.append('D')
		print(len(final))
		print(s.join(final))


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	s = stdin.readline()[:-1]
	(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 not l or not r:
		stdout.write(str(min(u, d, 1) * 2) + '\n')
		for i in range(min(u, d, 1)):
			stdout.write('UD')
	elif not u or not d:
		stdout.write(str(min(l, r, 1) * 2) + '\n')
		for i in range(min(r, l, 1)):
			stdout.write('RL')
	else:
		stdout.write(str((min(u, d) + min(l, r)) * 2) + '\n')
		for i in range(min(u, d)):
			stdout.write('U')
		for i in range(min(l, r)):
			stdout.write('L')
		for i in range(min(u, d)):
			stdout.write('D')
		for i in range(min(l, r)):
			stdout.write('R')
	stdout.write('\n')


col = int(input())
for _ in range(col):
	x = y = colU = colR = colL = colD = 0
	b = True
	p = input()
	for i in p:
		if i == 'U':
			colU += 1
			y += 1
		if i == 'L':
			colL += 1
			x -= 1
		if i == 'R':
			colR += 1
			x += 1
		if i == 'D':
			colD += 1
			y -= 1
		if x == 0 and y == 0:
			b = False
	if x == 0 and y == 0 and (b == True):
		print(0)
	if x > 0:
		p.replace('R', '', x)
		colR -= x
	elif x < 0:
		p.replace('L', '', abs(x))
		colL -= abs(x)
	if y > 0:
		p.replace('U', '', y)
		colU -= y
	elif y < 0:
		p.replace('D', '', abs(y))
		colD -= abs(y)
	p = 'U' * colU + 'R' * colR + 'D' * colD + 'L' * colL
	if colR == len(p) or colL == len(p) or colD == len(p) or (colU == len(p)):
		print(0)
		continue
	if colU == 0 and colD == 0:
		print(2)
		print('LR')
		continue
	if colL == 0 and colR == 0:
		print(2)
		print('UD')
		continue
	print(len(p))
	print(p)


t = int(input())
for _ in range(t):
	s = input()
	s = list(s)
	(l, r, u, d) = [0, 0, 0, 0]
	for i in s:
		if i == 'L':
			l += 1
		if i == 'R':
			r += 1
		if i == 'U':
			u += 1
		if i == 'D':
			d += 1
	minupdown = min(u, d)
	minrl = min(r, l)
	if minupdown == 0 and minrl == 0:
		print(0)
		continue
	if minupdown == 0 or minrl == 0:
		if minrl == 0:
			print(2)
			print('UD')
		else:
			print(2)
			print('RL')
		continue
	ans = ''
	xl = 'L' * minrl
	xr = 'R' * minrl
	xu = 'U' * minupdown
	xd = 'D' * minupdown
	ans = xr + xd + xl + xu
	print(len(ans))
	print(ans)


from collections import Counter
for _ in range(int(input())):
	s = input()
	cc = Counter(s)
	mh = min(cc['R'], cc['L'])
	mv = min(cc['U'], cc['D'])
	if mh == 0 and mv > 0:
		print(2)
		print('U' + 'D')
	elif mv == 0 and mh > 0:
		print(2)
		print('LR')
	elif mh == 0 and mv == 0:
		print(0)
	else:
		print(2 * (mh + mv))
		print('U' * mv + 'R' * mh + 'D' * mv + 'L' * mh)


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')


n = int(input())
for i in range(n):
	path = input()
	l = path.count('L')
	d = path.count('D')
	r = path.count('R')
	u = path.count('U')
	lr = min(l, r)
	ud = min(u, d)
	if lr == 0 and ud == 0:
		modifiedPath = ''
	elif lr == 0:
		modifiedPath = 'UD'
	elif ud == 0:
		modifiedPath = 'LR'
	else:
		modifiedPath = 'L' * lr + 'D' * ud + 'R' * lr + 'U' * ud
	print(len(modifiedPath), modifiedPath, 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)


import sys
import collections
input = sys.stdin.readline
N = int(input())
L = []
for _ in range(N):
	temp = input()
	L.append(temp)
for i in range(N):
	s = L[i]
	c = collections.Counter(s)
	c_rl = min(c['R'], c['L'])
	c_ud = min(c['U'], c['D'])
	if c_rl == 0 and c_ud == 0:
		print(0)
	elif c_rl == 0:
		print(2)
		print('UD')
	elif c_ud == 0:
		print(2)
		print('RL')
	else:
		ans = ['U'] * c_ud + ['R'] * c_rl + ['D'] * c_ud + ['L'] * c_rl
		print(len(ans))
		print(''.join(ans))


import sys

def main():
	for tc in range(int(input())):
		s = input()
		f = 0
		d = {}
		(x, y) = (0, 0)
		ans = []
		(l, r, u, d) = (0, 0, 0, 0)
		for i in range(len(s)):
			if s[i] == 'U':
				u += 1
			elif s[i] == 'D':
				d += 1
			elif s[i] == 'L':
				l += 1
			else:
				r += 1
		op = []
		if l + r <= 1 or l == 0 or r == 0:
			if u == 0 or d == 0:
				print(0)
				print()
			else:
				print(2)
				print('UD')
		elif u + d <= 1 or u == 0 or d == 0:
			if l == 0 or r == 0:
				print(0)
				print()
			else:
				print(2)
				print('LR')
		else:
			i = min(d, u)
			while i > 0:
				op.append('D')
				i -= 1
			i = min(l, r)
			while i > 0:
				op.append('R')
				i -= 1
			i = min(d, u)
			while i > 0:
				op.append('U')
				i -= 1
			i = min(l, r)
			while i > 0:
				op.append('L')
				i -= 1
			print(len(op))
			print(*op, sep='')
get_array = lambda : list(map(int, sys.stdin.readline().split()))
get_ints = lambda : map(int, sys.stdin.readline().split())
input = lambda : sys.stdin.readline().strip()
main()


for _ in range(int(input())):
	ans = ''
	s = input()
	x = min(s.count('L'), s.count('R'))
	y = min(s.count('U'), s.count('D'))
	if x == 0 and y == 0:
		x = x
	elif x == 0:
		y = 1
	elif y == 0:
		x = 1
	for i in range(y):
		ans += 'U'
	for i in range(x):
		ans += 'R'
	for i in range(y):
		ans += 'D'
	for i in range(x):
		ans += 'L'
	print(len(ans))
	print(ans)


for i in range(int(input())):
	s = input()
	l = r = u = 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
	if min(u, d) == 0 and l and r:
		print(2)
		print('LR')
	elif min(u, d) == 0 and min(l, r) == 0:
		print(0)
		print('')
	elif min(l, r) == 0 and u and d:
		print(2)
		print('UD')
	else:
		l = min(l, r)
		r = min(l, r)
		u = min(u, d)
		d = min(u, d)
		ans = r * ['R'] + d * ['D'] + l * ['L'] + u * ['U']
		print(len(ans))
		print(*ans, sep='')


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)


t = int(input())
for i in range(t):
	string = str(input())
	l = 0
	r = 0
	u = 0
	d = 0
	for i in range(len(string)):
		if string[i] == 'R':
			r += 1
		elif string[i] == 'L':
			l += 1
		elif string[i] == 'D':
			d += 1
		else:
			u += 1
	a = min(l, r)
	b = min(u, d)
	if a == 0 and b == 0:
		print(0)
		continue
	elif a == 0:
		print(2)
		print('UD')
		continue
	elif b == 0:
		print(2)
		print('LR')
		continue
	print(2 * (a + b))
	print('R' * a + 'U' * b + 'L' * a + 'D' * b)


from time import time
from random import randint

def solve(instructions):
	characters = ['R', 'U', 'L', 'D']
	array = [0] * 4
	print_array = []
	for e in instructions:
		array[0] += e == 'R'
		array[1] += e == 'U'
		array[2] += e == 'L'
		array[3] += e == 'D'
	horizontal = min(array[0], array[2])
	vertical = min(array[1], array[3])
	for i in range(0, 4, 2):
		for k in range(horizontal):
			print_array.append(characters[i])
		for k in range(vertical):
			print_array.append(characters[i + 1])
	if horizontal > 0 and vertical == 0:
		print_array = 'RL'
	if vertical > 0 and horizontal == 0:
		print_array = 'UD'
	print(len(print_array))
	print(''.join(print_array))

def submit():
	for case in range(int(input())):
		instructions = input()
		solve(instructions)

def tryOut():
	start_time = time()
	print(f'\nExecution time: {time() - start_time}s')
submit()


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)


for tt in range(int(input())):
	s = input()
	lst = list(s)
	x = 0
	y = 0
	for i in lst:
		if i == 'U':
			y += 1
		if i == 'D':
			y -= 1
		if i == 'L':
			x -= 1
		if i == 'R':
			x += 1
	if x > 0:
		while x != 0:
			lst.remove('R')
			x -= 1
	if x < 0:
		while x != 0:
			lst.remove('L')
			x += 1
	if y > 0:
		while y != 0:
			lst.remove('U')
			y -= 1
	if y < 0:
		while y != 0:
			lst.remove('D')
			y += 1
	l1 = set(lst)
	if len(l1) == 4:
		l = 0
		r = 0
		d = 0
		u = 0
		for i in lst:
			if i == 'R':
				r += 1
			if i == 'L':
				l += 1
			if i == 'U':
				u += 1
			if i == 'D':
				d += 1
		if l > r:
			ans1 = 'R' * r
			ans2 = 'L' * r
		else:
			ans1 = 'R' * l
			ans2 = 'L' * l
		if u > d:
			ans3 = 'U' * d
			ans4 = 'D' * d
		else:
			ans3 = 'U' * u
			ans4 = 'D' * u
		print(len(ans1 + ans2 + ans3 + ans4))
		print(ans1 + ans3 + ans2 + ans4)
	elif len(l1) == 3:
		if 'R' not in l1:
			print(2)
			print('UD')
		elif 'L' not in l1:
			print(2)
			print('UD')
		elif 'U' not in l1:
			print(2)
			print('LR')
		elif 'D' not in l1:
			print(2)
			print('LR')
	elif len(l1) == 2:
		if 'L' in l1 and 'R' in l1:
			print(2)
			print('LR')
		elif 'U' in l1 and 'D' in l1:
			print(2)
			print('UD')
		else:
			print(0)
			print()
	else:
		print(0)
		print()


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)


def func():
	st = input()
	L = st.count('L')
	R = st.count('R')
	D = st.count('D')
	U = st.count('U')
	if L == R:
		H = L
	elif L < R:
		H = L
	else:
		H = R
	if D == U:
		V = D
	elif D < U:
		V = D
	else:
		V = U
	if H == 0 and V != 0:
		print(2)
		print('DU')
	elif V == 0 and H != 0:
		print(2)
		print('LR')
	elif H == 0 and V == 0:
		print(0)
		print()
	else:
		count = 2 * (H + V)
		s = ''
		for i in range(V):
			s += 'U'
		for i in range(H):
			s += 'L'
		for i in range(V):
			s += 'D'
		for i in range(H):
			s += 'R'
		print(count)
		print(s)
for i in range(int(input())):
	func()


q = int(input())
for i in range(q):
	s = input()
	l = len(s)
	D = 0
	U = 0
	L = 0
	R = 0
	for i in range(l):
		if s[i] == 'D':
			D += 1
		elif s[i] == 'U':
			U += 1
		elif s[i] == 'L':
			L += 1
		else:
			R += 1
	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:
		if D > U:
			k = D - U
			D -= k
			l -= k
		elif U > D:
			k = U - D
			U -= k
			l -= k
		if L > R:
			k = L - R
			L -= k
			l -= k
		elif R > L:
			k = R - L
			R -= k
			l -= k
		print(l)
		print('U' * U + 'R' * R + 'D' * D + 'L' * L)


from collections import Counter
from sys import stdin
for _ in range(int(stdin.readline())):
	d = Counter(stdin.readline())
	(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{lr * 'L' + ud * 'U' + lr * 'R' + ud * 'D'}")


from collections import defaultdict
q = int(input())
while q:
	cnt = defaultdict(int)
	check = defaultdict(int)
	s = input()
	a = [i for i in s]
	(x, y) = (0, 0)
	it = 0
	fault = 0
	for i in a:
		cnt[i] += 1
		if i == 'U':
			x -= 1
		if i == 'D':
			x += 1
		if i == 'R':
			y += 1
		if i == 'L':
			y -= 1
		it += 1
		if (x != 0 or y != 0) and (x, y) in check:
			fault = 1
		if (x == 0 and y == 0) and it != len(a):
			fault = 1
		check[x, y] = 1
	if x != 0 or y != 0:
		fault = 1
	if fault:
		v = min(cnt['U'], cnt['D'])
		h = min(cnt['R'], cnt['L'])
		if v == 0:
			if h > 0:
				print(2)
				print('LR')
				q -= 1
				continue
		if h == 0:
			if v > 0:
				print(2)
				print('UD')
				q -= 1
				continue
		ans = ''
		for i in range(v):
			ans += 'U'
		for i in range(h):
			ans += 'R'
		for i in range(v):
			ans += 'D'
		for i in range(h):
			ans += 'L'
		print(len(ans))
		print(ans)
	else:
		print(len(a))
		print(s)
	q -= 1


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()


def robot(s):
	l = ['L', 'D', 'R', 'U']
	d = {i: 0 for i in l}
	for i in s:
		d[i] += 1
	n1 = min(d['L'], d['R'])
	n2 = min(d['D'], d['U'])
	if n1 == 0 and n2 == 0:
		ans2 = ''
	elif n1 == 0:
		ans2 = 'U' + 'D'
	elif n2 == 0:
		ans2 = 'L' + 'R'
	else:
		ans2 = 'L' * n1 + 'D' * n2 + 'R' * n1 + 'U' * n2
	ans1 = len(ans2)
	print(ans1)
	print(ans2)
t = int(input())
for i in range(t):
	s = input()
	robot(s)


import sys, itertools, math
T = int(sys.stdin.readline())
for _ in range(T):
	s = sys.stdin.readline().strip()
	U = s.count('U')
	D = s.count('D')
	L = s.count('L')
	R = s.count('R')
	if min([U, D, L, R]) >= 1:
		d = ''.join(['R'] * min(R, L) + ['D'] * min(U, D) + ['L'] * min(R, L) + ['U'] * min(U, D))
		print(len(d))
		print(d)
	elif min([L, R]) >= 1:
		print(2)
		print('LR')
	elif min([U, D]) >= 1:
		print(2)
		print('UD')
	else:
		print(0)


import sys
import math
t = int(input())
for _ in range(t):
	s = input()
	(l, r, d, u) = (0, 0, 0, 0)
	for i in range(len(s)):
		if s[i] == 'L':
			l += 1
		if s[i] == 'R':
			r += 1
		if s[i] == 'D':
			d += 1
		if s[i] == 'U':
			u += 1
	(L, R, D, U) = (min(l, r), min(l, r), min(d, u), min(d, u))
	if R != 0 and U != 0:
		print(L + R + D + U)
		ans = ''
		for i in range(U):
			ans += 'U'
		for i in range(R):
			ans += 'R'
		for i in range(D):
			ans += 'D'
		for i in range(L):
			ans += 'L'
		print(ans)
	else:
		if R == 0 and U == 0:
			print(0)
			print('')
		if R >= 1:
			print(2)
			print('LR')
		if D >= 1:
			print(2)
			print('UD')


n = int(input())
for t in range(n):
	s = input()
	f = {'D': 0, 'R': 0, 'U': 0, 'L': 0}
	for i in s:
		f[i] += 1
	if f['D'] == 0 and f['U'] == 0 and (f['L'] >= 1) and (f['R'] >= 1):
		print(2)
		print('LR')
		continue
	if f['R'] == 0 and f['L'] == 0 and (f['D'] >= 1) and (f['U'] >= 1):
		print(2)
		print('DU')
		continue
	if f['R'] > 1 and f['L'] > 1 and (min(f['D'], f['U']) == 0):
		print(2)
		print('LR')
		continue
	if f['D'] > 1 and f['U'] > 1 and (min(f['L'], f['R']) == 0):
		print(2)
		print('DU')
		continue
	jumlahD = min(f['D'], f['U'])
	jumlahU = jumlahD
	jumlahR = min(f['R'], f['L'])
	jumlahL = jumlahR
	print(jumlahD + jumlahU + jumlahR + jumlahL)
	ans = jumlahD * 'D' + jumlahR * 'R' + jumlahU * 'U' + +jumlahL * 'L'
	print(ans)


from sys import stdin, stdout
for i in range(int(input())):
	s = stdin.readline()
	r = s.count('R')
	u = s.count('U')
	l = s.count('L')
	d = s.count('D')
	r = l = min(r, l)
	u = d = min(u, d)
	if r == u == 0:
		stdout.write('0\n')
	elif r == 0 or u == 0:
		stdout.write('2\n')
		stdout.write('%s\n' % ('UD' if r == 0 else 'RL'))
	else:
		stdout.write('%d\n' % (r + u << 1))
		s = ['R' for i in range(r)] + ['U' for i in range(u)] + ['L' for i in range(l)] + ['D' for i in range(d)]
		stdout.write(''.join(s))
	stdout.write('\n')


from itertools import combinations_with_replacement
import sys
input = sys.stdin.buffer.readline
q = int(input())
for _ in range(q):
	x = input().decode()
	u = x.count('U')
	d = x.count('D')
	l = x.count('L')
	r = x.count('R')
	us = min(u, d)
	rs = min(l, r)
	if us == 0 and rs == 0:
		print(0)
	elif us * rs == 0:
		print(2)
		if us:
			print('UD')
		else:
			print('LR')
	else:
		print(rs * 2 + us * 2)
		if rs + us > 0:
			print('U' * us + 'L' * rs + 'D' * us + 'R' * rs)


q = int(input())
for Q in range(q):
	s = input()
	u = s.count('U')
	d = s.count('D')
	l = s.count('L')
	r = s.count('R')
	ud = min(u, d)
	rl = min(r, l)
	if ud == 0 and rl != 0:
		rl = 1
	if ud != 0 and rl == 0:
		ud = 1
	print((ud + rl) * 2)
	s = 'D' * ud + 'R' * rl + 'U' * ud + 'L' * rl
	print(s)


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)


from sys import stdin
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
t = int(input())
for i in range(t):
	s = input()
	u = s.count('U')
	d = s.count('D')
	l = s.count('L')
	r = s.count('R')
	z1 = min(u, d)
	z2 = min(l, r)
	if z2 == 0 and z1 != 0:
		print(2)
		print('UD')
	elif z1 == 0 and z2 != 0:
		print(2)
		print('LR')
	else:
		print((z1 + z2) * 2)
		print('U' * z1 + 'L' * z2 + 'D' * z1 + 'R' * z2)


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)


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


for _ in range(int(input())):
	a = [0, 0, 0, 0]
	q = {'L': 0, 'R': 1, 'U': 2, 'D': 3}
	s = input()
	for x in s:
		a[q[x]] += 1
	f = min(a[0], a[1])
	s = min(a[2], a[3])
	a[0] = f
	a[1] = f
	a[2] = s
	a[3] = s
	if a[2] == 0 and a[0] > 1:
		a[0] = 1
		a[1] = 1
	if a[0] == 0 and a[2] > 1:
		a[2] = 1
		a[3] = 1
	print(sum(a))
	if sum(a) != 0:
		print(a[2] * 'U' + a[1] * 'R' + a[3] * 'D' + a[0] * 'L')


import sys
n = int(input())
for i in range(n):
	s = sys.stdin.readline().rstrip()
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	ud = min(u, d)
	lr = min(l, r)
	if ud != 0 and lr != 0:
		print(ud * 2 + lr * 2)
		ans = 'U' * ud + 'L' * lr + 'D' * ud + 'R' * lr
		print(ans)
	elif ud == 0 and l != 0 and (r != 0):
		print(2)
		print('LR')
	elif lr == 0 and u != 0 and (d != 0):
		print(2)
		print('UD')
	else:
		print(0)
		print()


t = int(input())
for i in range(0, t):
	b = str(input())
	a = list(b)
	if a.count('R') == a.count('L'):
		g = a.count('L')
	else:
		g = min(a.count('R'), a.count('L'))
	if a.count('U') == a.count('D'):
		h = a.count('U')
	else:
		h = min(a.count('U'), a.count('D'))
	if h == 0 and g != 0:
		g = 1
	if g == 0 and h != 0:
		h = 1
	s = ''
	for j in range(0, g):
		s = s + 'R'
	for j in range(0, h):
		s = s + 'U'
	for j in range(0, g):
		s = s + 'L'
	for j in range(0, h):
		s = s + 'D'
	print(2 * (h + g))
	print(s)


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)


from collections import Counter
T = int(input())
for t in range(T):
	C = Counter(input())
	left_right_min = min(C['L'], C['R'])
	up_down_min = min(C['U'], C['D'])
	if left_right_min == 0 and up_down_min == 0:
		print(0)
		print()
	elif left_right_min == 0:
		print(2)
		print('UD')
	elif up_down_min == 0:
		print(2)
		print('LR')
	else:
		print((left_right_min + up_down_min) * 2)
		print('L' * left_right_min + 'D' * up_down_min + 'R' * left_right_min + 'U' * up_down_min)


t = int(input())
a = []
for i in range(t):
	a.append(input())
for i in a:
	j = []
	A = ''
	B = ''
	C = ''
	D = ''
	E = ''
	for p in i:
		j.append(p)
	u = j.count('U')
	d = j.count('D')
	l = j.count('L')
	r = j.count('R')
	b = min(u, d)
	c = min(l, r)
	if b == 0 and c == 0:
		print(0)
	elif b == 0:
		print(2)
		print('LR')
	elif c == 0:
		print(2)
		print('UD')
	else:
		for p in range(b):
			A += 'U'
			B += 'D'
		for p in range(c):
			C += 'R'
			D += 'L'
		E = A + C + B + D
		print(2 * (b + c))
		print(E)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	s = input().strip()
	mems = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	for i in s:
		mems[i] += 1
	mems['U'] = min(mems['U'], mems['D'])
	mems['R'] = min(mems['R'], mems['L'])
	if mems['U'] == 0 and mems['R'] != 0:
		print(2)
		print('LR')
	elif mems['R'] == 0 and mems['U'] != 0:
		print(2)
		print('UD')
	else:
		print(2 * (mems['U'] + mems['R']))
		print('U' * mems['U'] + 'R' * mems['R'] + 'D' * mems['U'] + 'L' * mems['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()


for i in range(int(input())):
	s = input()
	r = s.count('R')
	u = s.count('U')
	l = s.count('L')
	d = s.count('D')
	r = l = min(r, l)
	u = d = min(u, d)
	if r == u == 0:
		print('0')
	elif r == 0 or u == 0:
		print(2)
		print('UD' if r == 0 else 'RL', end='')
	else:
		print(r + u << 1)
		for i in range(r):
			print('R', end='')
		for i in range(u):
			print('U', end='')
		for i in range(l):
			print('L', end='')
		for i in range(d):
			print('D', end='')
	print()


from collections import defaultdict

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

def main():
	Q = int(input())
	for i in range(Q):
		s = input()
		L = 0
		R = 0
		U = 0
		D = 0
		for j in s:
			if j == 'L':
				L += 1
			elif j == 'R':
				R += 1
			elif j == 'U':
				U += 1
			else:
				D += 1
		a = min(L, R)
		b = min(U, D)
		if a == 0 and b == 0:
			print(0)
			print('')
		elif a == 0:
			print(2)
			print('UD')
		elif b == 0:
			print(2)
			print('LR')
		else:
			ans = (a + b) * 2
			print(ans)
			seq = 'L' * a + 'D' * b + 'R' * a + 'U' * b
			print(seq)
main()


q = int(input())
for i in range(q):
	s = input()
	n = len(s)
	d = {'U': 0, 'D': 0, 'R': 0, 'L': 0}
	for j in s:
		d[j] += 1
	if d['U'] > d['D']:
		n = n - d['U'] + d['D']
		d['U'] = d['D']
	else:
		n = n - d['D'] + d['U']
		d['D'] = d['U']
	if d['L'] > d['R']:
		n = n - d['L'] + d['R']
		d['L'] = d['R']
	else:
		n = n - d['R'] + d['L']
		d['R'] = d['L']
	if d['U'] == 0 and d['R'] == 0:
		print(0)
		print()
	elif d['U'] == 0:
		print(2)
		print('LR')
	elif d['R'] == 0:
		print(2)
		print('UD')
	else:
		print(n)
		s = 'R' * d['R'] + 'U' * d['U'] + 'L' * d['L'] + 'D' * d['D']
		print(s)


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)


for _ in range(int(input())):
	s = input()
	count = {'R': 0, 'L': 0, 'U': 0, 'D': 0}
	for i in range(len(s)):
		count[s[i]] += 1
	(l, r, u, d) = (count['L'], count['R'], count['U'], count['D'])
	if (min(l, r) == 0) ^ (min(u, d) == 0):
		if min(l, r) != 0:
			print(2)
			print('LR')
		elif min(u, d) != 0:
			print(2)
			print('UD')
		else:
			print(0)
	else:
		output = []
		output += ['U' for _ in range(min(count['U'], count['D']))]
		output += ['L' for _ in range(min(count['L'], count['R']))]
		output += ['D' for _ in range(min(count['U'], count['D']))]
		output += ['R' for _ in range(min(count['L'], count['R']))]
		print(len(output))
		print(''.join(output))


for i in range(int(input())):
	s = input()
	L = s.count('L')
	R = s.count('R')
	U = s.count('U')
	D = s.count('D')
	a = min(L, R)
	b = min(U, D)
	if a == 0 and b != 0:
		b = 1
	if b == 0 and a != 0:
		a = 1
	print(a * 2 + b * 2)
	print('R' * a + 'U' * b + 'L' * a + 'D' * b)


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)


N = int(input())
for _ in range(N):
	D = 0
	U = 0
	R = 0
	L = 0
	inst = input()
	for i in inst:
		if i == 'R':
			R += 1
		if i == 'L':
			L += 1
		if i == 'U':
			U += 1
		if i == 'D':
			D += 1
	if min(L, R) == 0 and min(U, D) != 0:
		print(2)
		print('UD')
	elif min(L, R) != 0 and min(U, D) == 0:
		print(2)
		print('RL')
	elif min(L, R) == 0 and min(U, D) == 0:
		print(0)
	else:
		res = 2 * min(R, L) + 2 * min(U, D)
		print(res)
		x = 'R' * min(R, L) + 'U' * min(U, D) + 'L' * min(R, L) + 'D' * min(U, D)
		print(x)


import math
t = int(input())
for i in range(t):
	l = 0
	r = 0
	u = 0
	d = 0
	result = ''
	vert = 0
	hor = 0
	steps = str(input())
	for item in steps:
		if item == 'L':
			l += 1
		if item == 'R':
			r += 1
		if item == 'D':
			d += 1
		if item == 'U':
			u += 1
	if u == 0 and d == 0 and (l == 0) and (r == 0):
		result = ''
	else:
		if u == 0 or d == 0:
			if l == 0 or r == 0:
				result = ''
			else:
				result = 'LR'
		if l == 0 or r == 0:
			if u == 0 or d == 0:
				result = ''
			else:
				result = 'UD'
		if (u == 0 or d == 0) and (r == 0 or l == 0):
			result = ''
	if u != 0 and d != 0 and (l != 0) and (r != 0):
		vert = min(u, d)
		hor = min(r, l)
		for k in range(vert):
			result += 'U'
		for k in range(hor):
			result += 'R'
		for k in range(vert):
			result += 'D'
		for k in range(hor):
			result += 'L'
	print(len(result))
	print(result)


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


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 ' ' * int(input()):
	s = input()
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	l = min(l, r)
	d = min(u, d)
	if l == 0 and d != 0:
		d = 1
	if d == 0 and l != 0:
		l = 1
	print(l * 2 + d * 2)
	print('L' * l + 'D' * d + 'R' * l + 'U' * d)


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)


import sys, collections
tc = int(sys.stdin.readline())
for _ in range(tc):
	arr = list(sys.stdin.readline().rstrip())
	res = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for i in arr:
		res[i] += 1
	hori = min(res['L'], res['R'])
	verti = min(res['U'], res['D'])
	for i in res:
		if i == 'L' or i == 'R':
			res[i] = hori
		if i == 'U' or i == 'D':
			res[i] = verti
	if hori and (not verti):
		print(2)
		print('LR')
	elif not hori and verti:
		print(2)
		print('UD')
	elif not hori and verti:
		print(0)
	else:
		ans = 'R' * res['R'] + 'U' * res['U'] + 'L' * res['L'] + 'D' * res['D']
		print(len(ans))
		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


from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import sys
sys.setrecursionlimit(10000000)
mod = 998244353

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

def I():
	return int(input())
from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7

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

def I():
	return int(input())
for _ in range(I()):
	s = Counter(input())
	MIN = float('inf')
	for (k, v) in s.items():
		MIN = min(MIN, v)
	if len(s) != 4:
		MIN = 0
	if MIN == 0:
		if s['R'] == 0 or s['L'] == 0:
			if s['U'] == 0 or s['D'] == 0:
				print(0)
			else:
				print(2)
				print('UD')
		elif s['U'] == 0 or s['D'] == 0:
			if s['R'] == 0 or s['L'] == 0:
				print(0)
			else:
				print(2)
				print('RL')
	else:
		ans = 0
		ans += min(s['R'], s['L']) * 2 + min(s['U'], s['D']) * 2
		ansS = 'U' * min(s['U'], s['D']) + 'R' * min(s['R'], s['L']) + 'D' * min(s['U'], s['D']) + 'L' * min(s['R'], s['L'])
		print(ans)
		print(ansS)


t = t = int(input())
while t:
	t -= 1
	s = input()
	freq = {}
	freq['D'] = freq['U'] = freq['L'] = freq['R'] = 0
	for x in s:
		freq[x] += 1
	ups = min(freq['U'], freq['D'])
	lefts = min(freq['L'], freq['R'])
	if ups == 0:
		if lefts != 0:
			ans = 2
			print(2)
			print('LR')
			continue
	elif lefts == 0:
		if ups != 0:
			print(2)
			print('UD')
			continue
	ans = 2 * ups + 2 * lefts
	s1 = 'D' * ups + 'R' * lefts + 'U' * ups + 'L' * lefts
	print(ans)
	print(s1)


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


import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	s = input()
	d = s.count('D')
	u = s.count('U')
	l = s.count('L')
	r = s.count('R')
	if min(r, l) == 0 and min(u, d) > 0:
		print(2)
		print('DU')
	elif min(u, d) == 0 and min(r, l) > 0:
		print(2)
		print('RL')
	elif min(r, l) == 0 and min(u, d) == 0:
		print(0)
		print()
	else:
		x = min(l, r)
		y = min(u, d)
		print(2 * x + 2 * y)
		print('U' * y + 'R' * x + 'D' * y + 'L' * x)


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())
for i in range(t):
	s = input()
	(lcount, rcount, ucount, dcount) = (0, 0, 0, 0)
	for x in s:
		if x == 'U':
			ucount += 1
		elif x == 'D':
			dcount += 1
		elif x == 'R':
			rcount += 1
		else:
			lcount += 1
	lr = min(lcount, rcount)
	ud = min(dcount, ucount)
	if ucount == 0 or dcount == 0:
		if lr == 0:
			print(0)
		else:
			print(2)
			print('LR')
	elif rcount == 0 or lcount == 0:
		if ud == 0:
			print(0)
		else:
			print(2)
			print('UD')
	else:
		print(2 * (ud + lr))
		print('U' * ud + 'L' * lr + 'D' * ud + 'R' * lr)


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


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


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')
	R = min(L, R)
	L = R
	U = min(U, D)
	D = U
	if L == 0 and D != 0:
		print('2')
		print('UD')
	elif D == 0 and L != 0:
		print('2')
		print('LR')
	elif D == 0 and L == 0:
		print('0')
		print()
	else:
		print(2 * (L + D))
		print('U' * U + 'R' * R + 'D' * D + 'L' * L)


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)


n = int(input())
for i in range(n):
	s = input()
	l_c = s.count('L')
	r_c = s.count('R')
	u_c = s.count('U')
	d_c = s.count('D')
	hor = min(l_c, r_c)
	ver = min(u_c, d_c)
	if ver == 0 and hor != 0:
		print(2)
		print('LR')
	elif hor == 0 and ver != 0:
		print(2)
		print('UD')
	else:
		print(2 * (hor + ver))
		print('U' * ver + 'L' * hor + 'D' * ver + 'R' * hor)


for _ in range(int(input())):
	arr = [0] * 4
	for i in input():
		if i == 'R':
			arr[0] += 1
		elif i == 'D':
			arr[1] += 1
		elif i == 'L':
			arr[2] += 1
		elif i == 'U':
			arr[3] += 1
	if arr[0] > arr[2]:
		arr[0] = arr[2]
	else:
		arr[2] = arr[0]
	if arr[1] > arr[3]:
		arr[1] = arr[3]
	else:
		arr[3] = arr[1]
	if arr[0] == 0:
		if arr[1] > 0 and arr[3] > 0:
			print(2)
			print('DU')
			continue
		else:
			print(0)
			continue
	if arr[1] == 0:
		if arr[0] > 0 and arr[2] > 0:
			print(2)
			print('LR')
			continue
		else:
			print(0)
			continue
	s = ''
	for i in range(arr[0]):
		s += 'R'
	for i in range(arr[1]):
		s += 'D'
	for i in range(arr[2]):
		s += 'L'
	for i in range(arr[3]):
		s += 'U'
	print(len(s))
	print(s)


n = int(input())
for i in range(n):
	s = ''
	a = input()
	LL = a.count('L')
	RR = a.count('R')
	UU = a.count('U')
	DD = a.count('D')
	if LL > RR:
		LL = RR
	else:
		RR = LL
	if UU > DD:
		UU = DD
	else:
		DD = UU
	if LL == 0 and UU > 1:
		(UU, DD) = (1, 1)
	if UU == 0 and RR > 1:
		(RR, LL) = (1, 1)
	print(LL * 2 + DD * 2)
	for j in range(UU):
		s += 'U'
	for j in range(RR):
		s += 'R'
	for j in range(DD):
		s += 'D'
	for j in range(LL):
		s += 'L'
	print(s)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	move = input().rstrip()
	cnt = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	for i in move:
		cnt[i] += 1
	y = min(cnt['U'], cnt['D'])
	x = min(cnt['L'], cnt['R'])
	if x == 0:
		if y == 0:
			print('0\n')
		else:
			print('2\nUD')
	elif y == 0:
		if x == 0:
			print('0\n')
		else:
			print('2\nLR')
	else:
		print((x + y) * 2)
		print('U' * y + 'L' * x + 'D' * y + 'R' * x)


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())
ans = []
dl = []
for i in range(q):
	ls = []
	s = input()
	r = s.count('R')
	l = s.count('L')
	u = s.count('U')
	d = s.count('D')
	rl = min(r, l)
	ud = min(u, d)
	if ud > 0 and rl > 0:
		a = 'R' * rl + 'U' * ud + 'L' * rl + 'D' * ud
		b = len(s) - abs(r - l) - abs(u - d)
	if ud == 0 and rl > 0:
		a = 'RL'
		b = 2
	if rl == 0 and ud > 0:
		a = 'UD'
		b = 2
	if rl == 0 and ud == 0:
		a = ' '
		b = 0
	dl.append(b)
	ans.append(a)
for i in range(q):
	print(dl[i])
	if dl[i] != 0:
		print(ans[i])
	else:
		continue


q = int(input())
for Q in range(q):
	s = input().strip().lower()
	u = min(s.count('u'), s.count('d'))
	r = min(s.count('r'), s.count('l'))
	if not u:
		if not r:
			print('0\n')
		else:
			print('2\nRL')
	elif not r:
		print('2\nUD')
	else:
		print(2 * u + 2 * r)
		print('U' * u + 'R' * r + 'D' * u + 'L' * r)


T = int(input())
for i in range(T):
	s = input().strip()
	L = 0
	R = 0
	U = 0
	D = 0
	for j in s:
		if j == 'L':
			L += 1
		if j == 'R':
			R += 1
		if j == 'U':
			U += 1
		if j == 'D':
			D += 1
	L = min([L, R])
	D = min([U, D])
	R = []
	if L > 0 and D > 0:
		R = ['L'] + ['U'] * D + ['R'] * L + ['D'] * D + ['L'] * (L - 1)
	if L == 0 and D > 0:
		R = ['U', 'D']
	if D == 0 and L > 0:
		R = ['L', 'R']
	print(len(R))
	print(''.join(R))


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')


from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input())
for _ in range(val()):
	s = st()
	up = min(s.count('U'), s.count('D'))
	left = min(s.count('L'), s.count('R'))
	s = ''
	flag = 0
	(down, right) = (up, left)
	if down == 0 and right >= 1:
		print(2)
		print('LR')
		continue
	if right == 0 and down >= 1:
		print(2)
		print('UD')
		continue
	if up > left:
		left -= 1
		s += 'L'
		while up > left:
			s += 'U'
			up -= 1
		s += 'R'
		right -= 1
		s += 'D' * (down - up - 1)
		down = up
		flag = 1
	else:
		while right > up:
			s += 'R'
			right -= 1
		s += 'RU'
		right -= 1
		up -= 1
		s += 'L' * (left - right)
		left = right
		down -= 1
	if down < 0 or up < 0 or left < 0 or (right < 0):
		print(0)
		print()
		continue
	if flag:
		s += 'R' * right + 'D' + 'D' * down + 'L' * left + 'U' * up
	else:
		s += 'L' * right + 'D' + 'D' * down + 'R' * left + 'U' * up
	print(len(s))
	print(s)


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)


def main():
	inps = eval(input())
	count = 0
	strs = []
	while count != inps:
		str = input()
		strs.append(str)
		count += 1
	for i in strs:
		str_arr = list(i)
		l = []
		r = []
		u = []
		b = []
		res = ''
		for j in str_arr:
			if j == 'L':
				l.append('L')
			elif j == 'R':
				r.append('R')
			elif j == 'U':
				u.append('U')
			elif j == 'D':
				b.append('D')
		longerH = l
		shorterH = r
		if len(l) < len(r):
			longerH = r
			shorterH = l
		longerV = u
		shorterV = b
		if len(u) < len(b):
			longerV = b
			shorterV = u
		longerH = [longerH[i] for i in range(len(shorterH))]
		longerV = [longerV[i] for i in range(len(shorterV))]
		if len(longerH) > 0 and len(longerV) == 0:
			res += 'LR'
		elif len(longerV) > 0 and len(longerH) == 0:
			res += 'UD'
		else:
			for i in longerV:
				res += i
			for l in shorterH:
				res += l
			for j in shorterV:
				res += j
			for k in longerH:
				res += k
		print(len(list(res)))
		print(res)
main()


t = int(input())
for h in range(t):
	s = input()
	(r, l, u, d) = (0, 0, 0, 0)
	for i in s:
		if i == 'R':
			r += 1
		if i == 'L':
			l += 1
		if i == 'U':
			u += 1
		if i == 'D':
			d += 1
	r = min(r, l)
	l = r
	u = min(u, d)
	d = u
	if u == 0:
		if l > 0:
			l = 1
			r = 1
	elif r == 0:
		if u > 0:
			u = 1
			d = 1
	print(r * 2 + u * 2)
	for i in range(r):
		print('R', end='')
	for i in range(u):
		print('U', end='')
	for i in range(r):
		print('L', end='')
	for i in range(u):
		print('D', end='')
	print()


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)


n = int(input())
for i in range(n):
	s = input()
	wr = ''
	wl = ''
	hu = ''
	hd = ''
	d = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	for k in range(len(s)):
		d[s[k]] += 1
	minh = min(d['U'], d['D'])
	minw = min(d['R'], d['L'])
	if minh == 0 and minw > 0:
		print(2)
		print('LR')
	elif minw == 0 and minh > 0:
		print(2)
		print('UD')
	else:
		for k in range(minh):
			hu += 'U'
			hd += 'D'
		for k in range(minw):
			wr += 'R'
			wl += 'L'
		print(minw * 2 + minh * 2)
		print(wr + hd + wl + hu)


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)


q = int(input())
for test in range(q):
	s = input()
	n_U = s.count('U')
	n_D = s.count('D')
	n_L = s.count('L')
	n_R = s.count('R')
	if n_U > n_D:
		n_U = n_D
	elif n_D > n_U:
		n_D = n_U
	if n_L > n_R:
		n_L = n_R
	elif n_R > n_L:
		n_R = n_L
	if n_L == 0:
		if n_U > 0:
			n_U = n_D = 1
	if n_U == 0:
		if n_L > 0:
			n_L = n_R = 1
	total = n_D + n_U + n_R + n_L
	gaba = ''
	gaba += n_U * 'U'
	gaba += n_L * 'L'
	gaba += n_D * 'D'
	gaba += n_R * 'R'
	print(total)
	print(gaba)


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)


q = int(input())
for o in range(q):
	s = input()
	if len(s) == 0:
		print(0)
	else:
		c1 = s.count('L')
		c2 = s.count('D')
		c3 = s.count('R')
		c4 = s.count('U')
		k = min(c1, c3)
		t = min(c2, c4)
		if k != 0 and t != 0:
			a = k * 'L' + t * 'D' + k * 'R' + t * 'U'
			print(len(a))
			print(a)
		elif k == 0 and t == 0:
			print(0)
		elif k == 0 and t != 0:
			print(2)
			print('UD')
		elif k != 0 and t == 0:
			print(2)
			print('LR')


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


t = int(input())
for i in range(t):
	s = input()
	l = len(s)
	d = 0
	r = 0
	u = 0
	left = 0
	for j in range(l):
		if s[j] == 'D':
			d += 1
		elif s[j] == 'U':
			u += 1
		elif s[j] == 'L':
			left += 1
		elif s[j] == 'R':
			r += 1
	m1 = min(left, r)
	m2 = min(u, d)
	if m1 > 0 and m2 > 0:
		print(2 * m1 + 2 * m2)
		print('U' * m2 + 'L' * m1 + 'D' * m2 + 'R' * m1)
	elif m1 == 0 and m2 == 0:
		print(0)
		print()
	elif m1 == 0:
		print(2)
		print('UD')
	elif m2 == 0:
		print(2)
		print('LR')


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)


from sys import stdin, stdout
import sys
INF = 100000000000.0
import bisect

def get_int():
	return int(stdin.readline().strip())

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

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

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
from collections import defaultdict
import math
for _ in range(int(stdin.readline())):
	s = get_string()
	d = {'R': 0, 'L': 0, 'U': 0, 'D': 0}
	for i in s:
		d[i] += 1
	ans = ''
	if (d['U'] == 0 or d['D'] == 0) and d['L'] > 0 and (d['R'] > 0):
		ans += 'LR'
		print(2)
		print(ans)
		continue
	if d['U'] > 0 and d['D'] > 0 and (d['L'] == 0 or d['R'] == 0):
		ans += 'UD'
		print(2)
		print(ans)
		continue
	for i in range(min(d['R'], d['L'])):
		ans += 'R'
	for i in range(min(d['U'], d['D'])):
		ans += 'U'
	for i in range(min(d['R'], d['L'])):
		ans += 'L'
	for i in range(min(d['U'], d['D'])):
		ans += 'D'
	print(len(ans))
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	d = {'U': 0, 'L': 0, 'R': 0, 'D': 0}
	for c in s:
		d[c] += 1
	m1 = min(d['U'], d['D'])
	m2 = min(d['R'], d['L'])
	if m1 == 0 and m2 == 0:
		print(0)
		continue
	if m1 == 0 and m2 != 1:
		m2 = 1
	if m2 == 0 and m1 != 1:
		m1 = 1
	print(2 * m1 + 2 * m2)
	for i in range(m1):
		print('U', end='')
	for i in range(m2):
		print('R', end='')
	for i in range(m1):
		print('D', end='')
	for i in range(m2):
		print('L', end='')
	print()


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


q = int(input())
for _ in range(q):
	s = input()
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	ud = min(u, d)
	lr = min(l, r)
	if ud == 0:
		lr = min(lr, 1)
	if lr == 0:
		ud = min(ud, 1)
	t = 'D' * ud + 'R' * lr + 'U' * ud + 'L' * lr
	print(len(t))
	print(t)


n = int(input())

def solve():
	(s, l, r, u, d) = (input(), 0, 0, 0, 0)
	for v in s:
		if v == 'R':
			r += 1
		if v == 'L':
			l += 1
		if v == 'U':
			u += 1
		if v == 'D':
			d += 1
	(h, v) = (min(r, l), min(u, d))
	if h > 0 and v > 0 or (h == 0 and v == 0):
		print(2 * h + 2 * v)
		print('R' * h + 'U' * v + 'L' * h + 'D' * v)
	else:
		print(2)
		print('RL' if h else 'UD')
for i in range(n):
	solve()


I = lambda : int(input())
ID = lambda : map(int, input().split())
IL = lambda : list(ID())
q = I()
for _ in range(q):
	s = list(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:
		if y != 0:
			y = 1
	if y == 0:
		if x != 0:
			x = 1
	print((x + y) * 2)
	print(str('R' * x + 'U' * y + 'L' * x + 'D' * y))


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


q = int(input())
for _ in range(q):
	s = list(input())
	(l, r, u, d) = (0, 0, 0, 0)
	for char in s:
		if char == 'L':
			l += 1
		if char == 'R':
			r += 1
		if char == 'U':
			u += 1
		if char == 'D':
			d += 1
	ans = [l + r + u + d, '']
	diff_lr = abs(l - r)
	diff_ud = abs(u - d)
	ans[0] -= diff_lr + diff_ud
	if r < l:
		l = r
	else:
		r = l
	if u < d:
		d = u
	else:
		u = d
	ans[1] = 'L' * l + 'D' * d + 'R' * r + 'U' * u
	if u == 0 or l == 0:
		ans[0] = 2
		if u == 0:
			ans[1] = 'LR'
		else:
			ans[1] = 'UD'
	if u == 0 and l == 0:
		ans[0] = 0
		ans[1] = ''
	print(*ans, sep='\n')


from collections import *
for _ in [0] * int(input()):
	c = Counter(input())
	a = min(c['L'], c['R'])
	b = min(c['U'], c['D'])
	b = min(b, (1, b)[a > 0])
	a = min(a, (1, a)[b > 0])
	print(2 * (a + b), 'L' * a + 'U' * b + 'R' * a + 'D' * b)


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)


import sys
tcs = int(sys.stdin.readline().rstrip())
for _ in range(tcs):
	inst = sys.stdin.readline().rstrip()
	r = 0
	l = 0
	d = 0
	u = 0
	for i in range(len(inst)):
		if inst[i] == 'R':
			r += 1
		elif inst[i] == 'L':
			l += 1
		elif inst[i] == 'D':
			d += 1
		else:
			u += 1
	if r > l:
		r = l
	else:
		l = r
	if u > d:
		u = d
	else:
		d = u
	if l + r + u + d == 0:
		print(0)
		continue
	if l == 0:
		d = 1
		u = 1
	if d == 0:
		l = 1
		r = 1
	print(r + l + d + u)
	print('R' * r + 'U' * u + 'L' * l + 'D' * d)


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)


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
		if s[i] == 'R':
			r += 1
		if s[i] == 'U':
			u += 1
		if s[i] == 'D':
			d += 1
	(u, d) = (min(u, d), min(u, d))
	(l, r) = (min(l, r), min(l, r))
	ans = ''
	if (u == 0 or d == 0) and l > 1 and (r > 1):
		ans = 'LR'
	elif (l == 0 or r == 0) and u > 1 and (d > 1):
		ans = 'UD'
	else:
		while l:
			ans += 'L'
			l -= 1
		while d:
			ans += 'D'
			d -= 1
		while r:
			ans += 'R'
			r -= 1
		while u:
			ans += 'U'
			u -= 1
	print(len(ans))
	print(ans)


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


for _ in range(int(input())):
	dic = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	s = input()
	for i in s:
		dic[i] += 1
	if dic['U']:
		if dic['D']:
			dic['U'] = dic['D'] = min(dic['U'], dic['D'])
		else:
			dic['U'] = 0
			if dic['L'] and dic['R']:
				dic['L'] = dic['R'] = 1
			else:
				dic['L'] = dic['R'] = 0
	else:
		dic['D'] = 0
		if dic['L'] and dic['R']:
			dic['L'] = dic['R'] = 1
		else:
			dic['L'] = dic['R'] = 0
	if dic['L']:
		if dic['R']:
			dic['L'] = dic['R'] = min(dic['L'], dic['R'])
		else:
			dic['L'] = 0
			if dic['U'] and dic['D']:
				dic['U'] = dic['D'] = 1
			else:
				dic['U'] = dic['D'] = 0
	else:
		dic['R'] = 0
		if dic['U'] and dic['D']:
			dic['U'] = dic['D'] = 1
		else:
			dic['U'] = dic['D'] = 0
	res = ''.join(['U' for i in range(dic['U'])]) + ''.join(['L' for i in range(dic['L'])]) + ''.join(['D' for i in range(dic['D'])]) + ''.join(['R' for i in range(dic['R'])])
	print(len(res))
	print(res)


for _ in range(int(input())):
	s = input()
	leftCnt = rightCnt = downCnt = upCnt = 0
	for ch in s:
		if ch == 'L':
			leftCnt += 1
		elif ch == 'R':
			rightCnt += 1
		elif ch == 'U':
			upCnt += 1
		elif ch == 'D':
			downCnt += 1
		else:
			raise Exception
	leftCnt = rightCnt = min(leftCnt, rightCnt)
	downCnt = upCnt = min(downCnt, upCnt)
	if not leftCnt and (not downCnt):
		print('0\n')
	elif not leftCnt:
		print('2\nUD')
	elif not upCnt:
		print('2\nRL')
	else:
		ret = 'R' * rightCnt + 'D' * downCnt + 'L' * leftCnt + 'U' * upCnt
		print('%d\n%s' % (len(ret), ret))


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)


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


from collections import Counter
for _ in range(int(input())):
	a = list(input())
	c = Counter(a)
	s = ''
	if len(c) == 4:
		if c['U'] < c['D']:
			c['D'] = c['U']
		else:
			c['U'] = c['D']
		if c['L'] < c['R']:
			c['R'] = c['L']
		else:
			c['L'] = c['R']
		s = s + 'U'
		c['U'] -= 1
		s = s + 'L'
		c['L'] -= 1
		while c['D'] != 0:
			s = s + 'D'
			c['D'] -= 1
		while c['R'] != 0:
			s = s + 'R'
			c['R'] -= 1
		while c['U'] != 0:
			s = s + 'U'
			c['U'] -= 1
		while c['L'] != 0:
			s = s + 'L'
			c['L'] -= 1
		print(len(s))
		print(s)
	elif len(c) == 3 or len(c) == 2:
		x = list(c.keys())
		s = ''
		if 'L' in x and 'R' in x:
			print(2)
			print('LR')
		elif 'U' in x and 'D' in x:
			print(2)
			print('UD')
		else:
			print(0)
	else:
		print(0)


q = int(input())
for qt in range(q):
	string = input()
	(l, r) = (0, 0)
	(u, d) = (0, 0)
	for i in string:
		if i == 'U':
			u = u + 1
		if i == 'D':
			d = d + 1
		if i == 'L':
			l = l + 1
		if i == 'R':
			r = r + 1
	mh = min(u, d)
	mv = min(l, r)
	if mv > 0 and mh > 0:
		print(mv + mv + mh + mh)
		print('L' * mv + 'U' * mh + 'R' * mv + 'D' * mh)
	elif mv == 0 and u > 0 and (d > 0):
		print(2)
		print('UD')
	elif mh == 0 and r > 0 and (l > 0):
		print(2)
		print('RL')
	else:
		print(0)


q = int(input())
for _ in range(q):
	s = input()
	moves = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for move in s:
		moves[move] += 1
	ver = min(moves['U'], moves['D'])
	hor = min(moves['L'], moves['R'])
	if ver == 0:
		if hor == 0:
			print(0)
			print('')
		else:
			print(2)
			print('LR')
	elif hor == 0:
		if ver == 0:
			print(0)
			print('')
		else:
			print(2)
			print('DU')
	else:
		print(2 * (ver + hor))
		print('L' * hor + 'D' * ver + 'R' * hor + 'U' * ver)


for _ in range(int(input())):
	a = input()
	if a == '':
		print(0)
		print(a)
		continue
	ud = min(a.count('U'), a.count('D'))
	rl = min(a.count('R'), a.count('L'))
	if ud == 0:
		if 'R' in a and 'L' in a:
			print(2)
			print('LR')
		else:
			print(0)
			print('')
	elif rl == 0:
		if 'U' in a and 'D' in a:
			print(2)
			print('UD')
		else:
			print(0)
			print('')
	else:
		print(2 * ud + 2 * rl)
		print('U' * ud + 'R' * rl + 'D' * ud + 'L' * rl)


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


for _ in range(int(input())):
	way = list(map(str, input()))
	s = {'R': 0, 'L': 0, 'U': 0, 'D': 0}
	for j in range(len(way)):
		s[way[j]] += 1
	m = abs(s['R'] - s['L'])
	m += abs(s['D'] - s['U'])
	if s['R'] == 0 or s['L'] == 0:
		if s['D'] > 0 and s['U'] > 0:
			print(2)
			print('UD')
			continue
		else:
			print(0)
			continue
	if s['U'] == 0 or s['D'] == 0:
		if s['R'] > 0 and s['L'] > 0:
			print(2)
			print('RL')
			continue
		else:
			print(0)
			continue
	tmp1 = min(s['U'], s['D'])
	tmp2 = min(s['L'], s['R'])
	print((tmp1 + tmp2) * 2)
	print('R' * tmp2 + 'U' * tmp1 + 'L' * tmp2 + 'D' * tmp1)


from collections import Counter
q = int(input())
for _ in range(q):
	cnt = Counter(list(input()))
	cnt['U'] = min(cnt['U'], cnt['D'])
	cnt['D'] = cnt['U']
	cnt['L'] = min(cnt['L'], cnt['R'])
	cnt['R'] = cnt['L']
	if cnt['D'] == 0 and cnt['R'] > 0:
		cnt['R'] = 1
		cnt['L'] = 1
	if cnt['R'] == 0 and cnt['D'] > 0:
		cnt['D'] = 1
		cnt['U'] = 1
	line = 'D' * cnt['D'] + 'L' * cnt['L'] + 'U' * cnt['U'] + 'R' * cnt['R']
	print(len(line))
	print(line)


t = int(input())
for _ in range(t):
	s = str(input())
	a = s.count('L')
	b = s.count('R')
	c = s.count('D')
	d = s.count('U')
	if a > 0 and b > 0 and (c > 0) and (d > 0):
		k = min(a, b)
		l = min(c, d)
		ans = max(a, b) - min(a, b) + max(c, d) - min(c, d)
		print(a + b + c + d - ans)
		st = min(a, b) * 'L' + min(c, d) * 'D' + min(a, b) * 'R' + min(c, d) * 'U'
		print(st)
	elif a == 0 or b == 0:
		if c == 0 or d == 0:
			print(0)
		else:
			print(2)
			print('DU')
	elif c == 0 or d == 0:
		if a == 0 or b == 0:
			print(0)
		else:
			print(2)
			print('LR')


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 _ in range(int(input())):
	l = list(input())
	u = l.count('U')
	d = l.count('D')
	le = l.count('L')
	r = l.count('R')
	if min(u, d) == 0 and min(le, r) == 0:
		print(0)
	elif min(u, d) == 0:
		print(2)
		print('LR')
	elif min(le, r) == 0:
		print(2)
		print('UD')
	else:
		out = 'U' * min(u, d) + 'L' * min(le, r) + 'D' * min(u, d) + 'R' * min(le, r)
		print(2 * (min(u, d) + min(le, r)))
		print(out)


def func(s):
	d = {'R': 0, 'U': 0, 'L': 0, 'D': 0}
	for i in s:
		if i == 'R':
			d['R'] += 1
		elif i == 'U':
			d['U'] += 1
		elif i == 'L':
			d['L'] += 1
		else:
			d['D'] += 1
	r = min(d['R'], d['L'])
	l = r
	u = min(d['U'], d['D'])
	d = u
	if r == 0:
		if u == 0:
			return (0, ' ')
		else:
			return (2, 'UD')
	elif d == 0:
		if r == 0:
			return (0, ' ')
		else:
			return (2, 'RL')
	else:
		return (2 * r + 2 * u, r * 'R' + d * 'D' + l * 'L' + u * 'U')
q = int(input())
for _ in range(q):
	s = input()
	(n, sub) = (func(s)[0], func(s)[1])
	print(n)
	print(sub)


T = int(input())
for t in range(T):
	inst = input()
	if 'U' not in inst or 'D' not in inst:
		if 'R' not in inst or 'L' not in inst:
			print(0)
		else:
			print(2)
			print('LR')
		continue
	elif 'R' not in inst or 'L' not in inst:
		if 'U' not in inst or 'D' not in inst:
			print(0)
		else:
			print(2)
			print('UD')
		continue
	x_R = 0
	x_L = 0
	y_D = 0
	y_U = 0
	for i in inst:
		if i == 'R':
			x_R += 1
		elif i == 'L':
			x_L += 1
		elif i == 'U':
			y_U += 1
		else:
			y_D += 1
	final = ''
	temp = min(x_R, x_L)
	temp2 = min(y_U, y_D)
	final += 'R' * temp
	final += 'U' * temp2
	final += 'L' * temp
	final += 'D' * temp2
	if len(final) == 0:
		print(0)
		continue
	print(len(final))
	print(final)


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)


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

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

def binaryToDecimal(n):
	return int(n, 2)

def solve():
	s = list(input())
	count = {'D': 0, 'L': 0, 'R': 0, 'U': 0}
	for i in s:
		count[i] += 1
	ud_count = min(count['U'], count['D'])
	lr_count = min(count['L'], count['R'])
	if ud_count == 0 and lr_count != 0:
		print(2)
		print('LR')
		return
	if ud_count != 0 and lr_count == 0:
		print(2)
		print('DU')
		return
	ans = 2 * ud_count + 2 * lr_count
	print(ans)
	for i in range(ud_count):
		print('D', end='')
	for i in range(lr_count):
		print('R', end='')
	for i in range(ud_count):
		print('U', end='')
	for i in range(lr_count):
		print('L', end='')
	print()
t = int(input())
for _ in range(t):
	solve()


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()


for _ in range(int(input())):
	s = input()
	(l, r, d, u) = (s.count('L'), s.count('R'), s.count('D'), s.count('U'))
	if max(min(d, u), min(l, r)) == 0:
		print(0)
		print()
		continue
	if min(d, u) == 0:
		print(2)
		print('LR')
		continue
	if min(l, r) == 0:
		print(2)
		print('DU')
		continue
	ans = 'L' * min(l, r) + 'D' * min(u, d) + 'R' * min(l, r) + 'U' * min(u, d)
	print(len(ans))
	print(ans)


q = int(input())
for _ in range(q):
	s = str(input())
	n = len(s)
	d = {}
	for i in range(n):
		if s[i] not in d:
			d[s[i]] = 1
		else:
			d[s[i]] += 1
	if len(d) == 1:
		print(0)
		print('')
	elif len(d) == 2:
		if 'R' in d and 'L' in d:
			print(2)
			print('RL')
		elif 'U' in d and 'D' in d:
			print(2)
			print('UD')
		elif 'R' in d and 'U' in d:
			print(0)
			print('')
		elif 'R' in d and 'D' in d:
			print(0)
			print('')
		elif 'L' in d and 'U' in d:
			print(0)
			print('')
		else:
			print(0)
			print('')
	elif len(d) == 3:
		if 'R' in d and 'L' in d:
			print(2)
			print('RL')
		else:
			print(2)
			print('UD')
	else:
		ans = n - abs(d['L'] - d['R']) - abs(d['U'] - d['D'])
		print(ans)
		print('L' * min(d['L'], d['R']) + 'D' * min(d['U'], d['D']) + 'R' * min(d['L'], d['R']) + 'U' * min(d['U'], d['D']))


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)


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


d = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
for x in range(int(input())):
	s = input()
	ans = len(s)
	s_ans = ''
	d['L'] = s.count('L')
	d['R'] = s.count('R')
	d['U'] = s.count('U')
	d['D'] = s.count('D')
	ans -= abs(d['L'] - d['R']) + abs(d['U'] - d['D'])
	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']
	s_ans = 'U' * d['U'] + 'R' * d['R'] + 'D' * d['D'] + 'L' * d['L']
	if len(set(s_ans)) == 2:
		print(2)
		print(s_ans[0] + s_ans[-1])
	elif ans == 0:
		print(ans)
		print()
	else:
		print(ans)
		print(s_ans)


q = int(input())
for loop in range(q):
	S = input()
	u = 0
	l = 0
	r = 0
	d = 0
	for i in S:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	u = min(u, d)
	d = u
	l = min(l, r)
	r = l
	if u == 0 and l > 0:
		l = 1
		r = 1
	elif l == 0 and u > 0:
		d = 1
		u = 1
	print(u + d + l + r)
	ans = []
	for i in range(u):
		ans += 'U'
	for i in range(l):
		ans += 'L'
	for i in range(u):
		ans += 'D'
	for i in range(r):
		ans += 'R'
	print(''.join(ans))


n = int(input())
for nn in range(n):
	instructions = list(input())
	(num_of_L, num_of_R, num_of_U, num_of_D) = (0, 0, 0, 0)
	for el in instructions:
		if el == 'L':
			num_of_L += 1
		elif el == 'R':
			num_of_R += 1
		elif el == 'U':
			num_of_U += 1
		else:
			num_of_D += 1
	if 'R' in instructions and 'L' in instructions or ('U' in instructions and 'D' in instructions):
		min_L_R = min(num_of_L, num_of_R)
		min_U_D = min(num_of_U, num_of_D)
		if min_L_R == 0:
			print(2)
			print('UD')
		elif min_U_D == 0:
			print(2)
			print('LR')
		else:
			print(min_L_R * 2 + min_U_D * 2)
			print('R' * min_L_R + 'U' * min_U_D + 'L' * min_L_R + 'D' * min_U_D)
	else:
		print(0)
		print()


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)


for _ in range(int(input())):
	u = 0
	d = 0
	l = 0
	r = 0
	code = input()
	for i in code:
		if i == 'U':
			u += 1
		elif i == 'D':
			d += 1
		elif i == 'L':
			l += 1
		elif i == 'R':
			r += 1
	if u > d:
		u = d
	else:
		d = u
	if l > r:
		l = r
	else:
		r = l
	if u == 0:
		if r > 1:
			r = 1
			l = 1
	if r == 0:
		if u > 1:
			u = 1
			d = 1
	ans = u + d + l + r
	new_path = 'U' * u + 'R' * r + 'D' * d + 'L' * l
	print(ans)
	print(new_path)


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)


q = int(input())
for x in range(q):
	s = [e for e in input()]
	l = s.count('L')
	r = s.count('R')
	d = s.count('D')
	u = s.count('U')
	lr = min(l, r)
	du = min(d, u)
	if lr == 0 and du == 0:
		print(0)
	elif lr == 0:
		print(2)
		print('DU')
	elif du == 0:
		print(2)
		print('LR')
	else:
		print(lr * 2 + du * 2)
		print('D' * du + 'R' * lr + 'U' * du + 'L' * lr)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	sets = set(s)
	if len(sets) == 1:
		print(0)
		print()
	elif len(sets) == 2:
		if 'L' in sets and 'R' in sets:
			print(2)
			print('LR')
		elif 'D' in sets and 'U' in sets:
			print(2)
			print('UD')
		else:
			print(0)
			print()
	elif len(sets) == 3:
		if 'L' in sets and 'R' in sets and ('D' in sets):
			print(2)
			print('LR')
		elif 'L' in sets and 'R' in sets and ('U' in sets):
			print(2)
			print('LR')
		elif 'R' in sets and 'U' in sets and ('D' in sets):
			print(2)
			print('UD')
		else:
			print(2)
			print('UD')
	else:
		cL = s.count('L')
		cR = s.count('R')
		cU = s.count('U')
		cD = s.count('D')
		miniLR = min(cL, cR)
		miniUD = min(cU, cD)
		s = 'R' * miniLR + 'U' * miniUD + 'L' * miniLR + 'D' * miniUD
		print(len(s))
		print(s)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7
tt = int(input())
for y in range(tt):
	a = input()
	if len(a) == 0:
		print(0)
		print(a)
		continue
	l = a.count('L')
	r = a.count('R')
	u = a.count('U')
	d = a.count('D')
	ll = min(l, r)
	uu = min(u, d)
	if uu == 0 and ll > 0:
		print(2)
		print('LR')
		continue
	if ll == 0 and uu > 0:
		print(2)
		print('UD')
		continue
	print((ll + uu) * 2)
	print(ll * 'R', end='')
	print(uu * 'U', end='')
	print(ll * 'L', end='')
	print(uu * 'D')


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)


import collections

def main():
	q = int(input())
	for i in range(q):
		s = input()
		direct = collections.defaultdict(int)
		h = 0
		v = 0
		for d in s:
			direct[d] = direct[d] + 1
		h = min(direct['R'], direct['L'])
		v = min(direct['U'], direct['D'])
		if h == 0 and v == 0:
			h = 0
			v = 0
		elif h == 0:
			v = 1
		elif v == 0:
			h = 1
		ans = ['U'] * v + ['R'] * h + ['D'] * v + ['L'] * h
		print((h + v) * 2)
		print(''.join(ans))
main()


for _ in range(int(input())):
	s = input()
	a = min(s.count('L'), s.count('R'))
	b = min(s.count('U'), s.count('D'))
	final = 2 * (a + b)
	fstr = a * 'L' + b * 'D' + a * 'R' + b * 'U'
	if a == 0 and b != 0:
		final = 2
		fstr = 'UD'
	elif a != 0 and b == 0:
		final = 2
		fstr = 'LR'
	print(final)
	print(fstr)


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 _ in range(t):
	instructions = list(input())
	r = instructions.count('R')
	l = instructions.count('L')
	u = instructions.count('U')
	d = instructions.count('D')
	diff1 = r - l
	if diff1 > 0:
		r = l
	else:
		l = r
	diff2 = u - d
	if diff2 > 0:
		u = d
	else:
		d = u
	if r == 0 and d == 0:
		print(0)
	elif r > 0 and d > 0:
		print(2 * r + 2 * d)
	elif u == 0:
		r = 1
		l = 1
		print(2)
	else:
		u = 1
		d = 1
		print(2)
	print('R' * r + 'U' * u + 'L' * l + 'D' * d)


q = int(input())
while q > 0:
	q -= 1
	u = d = l = r = ud = lr = 0
	newStr = ''
	s = input()
	for ch in s:
		if ch == 'U':
			u += 1
		elif ch == 'D':
			d += 1
		elif ch == 'L':
			l += 1
		elif ch == 'R':
			r += 1
	ud = min(u, d)
	lr = min(l, r)
	if not ud and lr:
		lr = 1
	elif not lr and ud:
		ud = 1
	newStr += 'U' * ud + 'L' * lr + 'D' * ud + 'R' * lr
	print(ud * 2 + lr * 2)
	print(newStr)


T = int(input())
for _ in range(0, T):
	A = list()
	s = input()
	u = 0
	d = 0
	l = 0
	r = 0
	for i in s:
		if i == 'U':
			u += 1
		elif i == 'D':
			d += 1
		elif i == 'L':
			l += 1
		else:
			r += 1
	u = d = min(u, d)
	l = r = min(l, r)
	S = ''
	if u and d and l and r:
		while u != 0:
			u -= 1
			S += 'U'
		while r != 0:
			r -= 1
			S += 'R'
		while d != 0:
			d -= 1
			S += 'D'
		while l != 0:
			l -= 1
			S += 'L'
	elif r and l:
		S += 'LR'
	elif u and d:
		S += 'UD'
	print(len(S))
	print(S)


def walk(str):
	dic = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for i in str:
		dic[i] += 1
	l = r = min(dic['L'], dic['R'])
	u = d = min(dic['U'], dic['D'])
	if u == 0 and l != 0:
		l = r = 1
	elif u != 0 and l == 0:
		u = d = 1
	print(l + u + r + d)
	ans = r * 'R' + u * 'U' + l * 'L' + d * 'D'
	print(ans)

def main():
	q = int(input())
	while q > 0:
		str = input()
		walk(str)
		q -= 1
main()


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()


from math import *
t = int(input())
for _ in range(t):
	s = input()
	a = 0
	b = 0
	c = 0
	d = 0
	for i in s:
		if i == 'L':
			a = a + 1
		elif i == 'R':
			b = b + 1
		elif i == 'U':
			c = c + 1
		else:
			d = d + 1
	x = min(a, b)
	y = min(c, d)
	if x == 0 and y == 0:
		print(0)
		print()
	elif x == 0 and y > 0:
		print(2)
		print('UD')
	elif x > 0 and y == 0:
		print(2)
		print('LR')
	else:
		print(2 * (x + y))
		print(x * 'R' + y * 'U' + 1 * 'L' + (y - 1) * 'D' + (x - 1) * 'L' + 'D')


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


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)


def solve():
	s = str(input())
	(l, r, u, d) = (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
	h = min(l, r)
	v = min(u, d)
	if h > 0 and v > 0 or (h == 0 and v == 0):
		print(2 * h + 2 * v)
		print('R' * h + 'U' * v + 'L' * h + 'D' * v)
	else:
		print(2)
		print('LR' if h else 'UD')
t = int(input())
while t:
	solve()
	t -= 1


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 collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY, log as LOG
from sys import stdin, stdout
INPUT = stdin.readline
PRINT = stdout.write

def player1():
	print('')

def player2():
	print('')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def factors(x):
	ans = []
	for i in range(1, MC(SQRT(x)) + 1):
		if x % i == 0:
			ans.append(i)
			if x % (x // i) == 0:
				ans.append(x // i)
	return ans

def checkPath(source, destination, g):
	visited = [0] * 101
	q = Q()
	q.append(source)
	visited[source] = 1
	while q:
		node = q.popleft()
		if node == destination:
			return 1
		for v in g[node]:
			if not visited[v]:
				q.append(v)
				visited[v] = 1
	return 0

def main():
	for _ in range(int(INPUT())):
		s = INPUT()
		(r, u, l, d) = (0, 0, 0, 0)
		for v in s:
			if v == 'U':
				u += 1
			elif v == 'R':
				r += 1
			elif v == 'D':
				d += 1
			elif v == 'L':
				l += 1
		LR = min(l, r)
		UD = min(u, d)
		if LR == 0 and UD != 0:
			UD = 1
		if UD == 0 and LR != 0:
			LR = 1
		ans = 'R' * LR + 'U' * UD + 'L' * LR + 'D' * UD
		PRINT('%d\n%s\n' % (len(ans), ans))
main()


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)


t = int(input())
while t > 0:
	s = input()
	l = s.count('L')
	u = s.count('U')
	r = s.count('R')
	d = s.count('D')
	h = min(l, r)
	v = min(u, d)
	l -= h
	r -= h
	u -= v
	d -= v
	arr = ''
	if h == 0 and v == 0:
		arr = ''
	elif h == 0:
		arr = 'UD'
	elif v == 0:
		arr = 'LR'
	else:
		for i in range(h):
			arr += 'R'
		for i in range(v):
			arr += 'D'
		for i in range(h):
			arr += 'L'
		for i in range(v):
			arr += 'U'
	print(len(arr))
	print(arr)
	t -= 1


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)


for i in range(int(input())):
	s = input()
	(mu, md, ml, mr) = (0, 0, 0, 0)
	for ch in s:
		if ch == 'U':
			mu += 1
		elif ch == 'D':
			md += 1
		elif ch == 'L':
			ml += 1
		else:
			mr += 1
	mih = min(ml, mr)
	miv = min(mu, md)
	if mih == 0 and miv == 0:
		print(0)
	elif mih == 0:
		print(2)
		print('UD')
	elif miv == 0:
		print(2)
		print('LR')
	else:
		print(2 * (miv + mih))
		print('U' * miv + 'L' * mih + 'D' * miv + 'R' * mih)


for _ in range(int(input())):
	s = input()
	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 == 0:
		u = d = min(u, 1)
	if u == 0:
		l = r = min(l, 1)
	ans = 'D' * d + 'R' * r + 'U' * u + 'L' * l
	print(len(ans))
	print(ans)


from collections import defaultdict
t = int(input())
for _ in range(t):
	a = list(input())
	counts = defaultdict(lambda : 0)
	for c in a:
		counts[c] += 1
	ud = min(counts['U'], counts['D'])
	lr = min(counts['L'], counts['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('U' * ud + 'R' * lr + 'D' * ud + 'L' * lr)


q = int(input())
for _ in range(q):
	s = input()
	d = 0
	l = 0
	r = 0
	u = 0
	for i in s:
		if i == 'L':
			l += 1
		if i == 'D':
			d += 1
		if i == 'U':
			u += 1
		if i == 'R':
			r += 1
	n = len(s) - abs(r - l) - abs(d - u)
	(d, u) = (min(d, u), min(d, u))
	(r, l) = (min(r, l), min(r, l))
	if d == 0 and r != 0:
		r = 1
		l = 1
		n = 2
	if r == 0 and d != 0:
		d = 1
		u = 1
		n = 2
	print(n)
	print('R' * r + 'D' * d + 'L' * l + 'U' * u)


T = int(input())
for kase in range(T):
	s = input()
	cnt = dict()
	(cnt['L'], cnt['R'], cnt['U'], cnt['D']) = (0, 0, 0, 0)
	for c in s:
		cnt[c] += 1
	ans = ''
	if min(cnt['L'], cnt['R']) == 0:
		if min(cnt['U'], cnt['D']) >= 1:
			ans = 'UD'
	elif min(cnt['U'], cnt['D']) == 0:
		if min(cnt['L'], cnt['R']) >= 1:
			ans = 'LR'
	else:
		h = min(cnt['L'], cnt['R'])
		v = min(cnt['U'], cnt['D'])
		ans = 'U' * v + 'L' * h + 'D' * v + 'R' * h
	print(len(ans))
	print(ans)


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)


testes = int(input())
for t in range(testes):
	comandos = list(input())
	comandos.sort()
	d = 0
	l = 0
	r = 0
	u = 0
	for k in range(len(comandos)):
		if comandos[k] == 'D':
			d += 1
		elif comandos[k] == 'L':
			l += 1
		elif comandos[k] == 'R':
			r += 1
		else:
			u += 1
	if l <= r:
		r = l
	else:
		l = r
	if u <= d:
		d = u
	else:
		u = d
	if r == 0 and u > 0:
		u = 1
		d = 1
	if u == 0 and r > 0:
		l = 1
		r = 1
	print(d + l + u + r)
	string = ''
	for i in range(l // 2):
		string += 'L'
	for i in range(u):
		string += 'U'
	for i in range(r):
		string += 'R'
	for i in range(d):
		string += 'D'
	for i in range(l - l // 2):
		string += 'L'
	print(string)


import sys
q = int(sys.stdin.readline())
ans_arr = []
for i in range(q):
	s = sys.stdin.readline().strip()
	l = 0
	r = 0
	u = 0
	d = 0
	for x in range(len(s)):
		if s[x] == 'L':
			l += 1
		elif s[x] == 'R':
			r += 1
		elif s[x] == 'U':
			u += 1
		elif s[x] == 'D':
			d += 1
	min_h = min(l, r)
	min_v = min(u, d)
	ans = ''
	if min_h == 0 and min_v != 0:
		ans = 'UD'
	elif min_v == 0 and min_h != 0:
		ans = 'LR'
	else:
		for g in range(min_v):
			ans += 'U'
		for g in range(min_h):
			ans += 'R'
		for g in range(min_v):
			ans += 'D'
		for g in range(min_h):
			ans += 'L'
	tmp = []
	tmp.append(len(ans))
	tmp.append(ans)
	ans_arr.append(tmp)
for h in range(len(ans_arr)):
	print(ans_arr[h][0])
	print(ans_arr[h][1])


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)


for _ in range(int(input())):
	s = input()
	cnt = [0, 0, 0, 0]
	for i in s:
		if i == 'L':
			cnt[0] += 1
		elif i == 'R':
			cnt[1] += 1
		elif i == 'U':
			cnt[2] += 1
		else:
			cnt[3] += 1
	x = min(cnt[0], cnt[1])
	y = min(cnt[2], cnt[3])
	if x == 0:
		if y == 0:
			print('0')
		else:
			print('2\nDU')
	elif y == 0:
		print('2\nLR')
	else:
		print(2 * (x + y))
		print('L' * x + 'D' * y + 'R' * x + 'U' * y)


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


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
for _ in range(int(input())):
	s = input()
	d = {l: 0 for l in 'UDRL'}
	for x in s:
		d[x] += 1
	if d['U'] and d['D'] and d['L'] and d['R']:
		r = 'U' * min(d['U'], d['D']) + 'R' * min(d['R'], d['L']) + 'D' * min(d['U'], d['D']) + 'L' * min(d['R'], d['L'])
	elif (not d['U'] or not d['D']) and (d['R'] and d['L']):
		r = 'RL'
	elif (not d['R'] or not d['L']) and (d['U'] and d['D']):
		r = 'UD'
	else:
		r = ''
	print(len(r))
	print(r)


for _ in [0] * int(input()):
	c = (*map(input().count, 'LRUD'),)
	a = min(c[:2])
	b = min(c[2:])
	a = (min(1, a), a)[b > 0]
	b = (min(1, b), b)[a > 0]
	print(2 * (a + b), 'L' * a + 'U' * b + 'R' * a + 'D' * b)


n = int(input())
hor = 0
vert = 0
for i in range(n):
	s = input()
	R = s.count('R')
	L = s.count('L')
	U = s.count('U')
	D = s.count('D')
	hor += R - L
	vert += U - D
	R = min(R, L)
	L = R
	U = min(U, D)
	D = U
	if R == 0 and U == 0:
		print(0)
	else:
		if R == 0:
			U = 1
			D = 1
		if U == 0:
			R = 1
			L = 1
		print(R + L + U + D)
		print('R' * R + 'U' * U + 'L' * L + 'D' * D)


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


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def solution(s):
	counts = defaultdict(int)
	for c in s:
		counts[c] += 1
	counts['L'] = min(counts['L'], counts['R'])
	counts['R'] = min(counts['L'], counts['R'])
	counts['U'] = min(counts['U'], counts['D'])
	counts['D'] = min(counts['U'], counts['D'])
	res = [''] * 4
	if counts['U'] and counts['L']:
		(res[0], res[2]) = ('U' * counts['U'], 'D' * counts['D'])
		(res[1], res[3]) = ('R' * counts['R'], 'L' * counts['L'])
	elif counts['L']:
		res = ['L', 'R']
	elif counts['U']:
		res = ['U', 'D']
	res = ''.join(res)
	write(len(res))
	write(res)

def main():
	for _ in range(r_int()):
		s = input()
		solution(s)
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


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')


t = int(input())
cd = 0
cu = 0
cl = 0
cr = 0
while t:
	cd = 0
	cu = 0
	cl = 0
	cr = 0
	s = input().replace('\n', '')
	for l in s:
		if l == 'D':
			cd = cd + 1
		elif l == 'U':
			cu = cu + 1
		elif l == 'L':
			cl = cl + 1
		else:
			cr = cr + 1
	rl = min(cr, cl)
	ud = min(cd, cu)
	if not rl:
		if ud:
			print(2)
			print('UD')
		else:
			print(0)
			print('')
	elif not ud:
		if rl:
			print(2)
			print('LR')
		else:
			print(0)
			print('')
	else:
		print(2 * rl + 2 * ud)
		print(rl * 'R' + ud * 'U' + rl * 'L' + ud * 'D')
	t = t - 1


q = int(input())
for _ in range(q):
	s = input()
	(l, r, d, u) = (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
	l = min(l, r)
	r = l
	u = min(u, d)
	d = u
	if d == 0 and u == 0:
		if l is not 0:
			print(2)
			print('LR')
		else:
			print(0)
			print('')
	elif l == 0 and r == 0:
		if u is not 0:
			print(2)
			print('UD')
		else:
			print(0)
			print('')
	else:
		print(2 * (l + d))
		ans = []
		for i in range(u):
			ans.append('U')
		for i in range(l):
			ans.append('L')
		for i in range(u):
			ans.append('D')
		for i in range(l):
			ans.append('R')
		print(''.join(map(str, ans)))


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)


def f(s):
	d = {}
	d['D'] = 0
	d['U'] = 0
	d['R'] = 0
	d['L'] = 0
	for i in range(len(s)):
		if s[i] not in d:
			d[s[i]] = 1
		else:
			d[s[i]] = d[s[i]] + 1
	d['U'] = min(d['U'], d['D'])
	d['D'] = d['U']
	d['L'] = min(d['L'], d['R'])
	d['R'] = d['L']
	if d['U'] == 0 and d['R'] != 0:
		print(2)
		return 'LR'
	elif d['R'] == 0 and d['U'] != 0:
		print(2)
		return 'UD'
	sum = d['U'] * 2 + d['L'] * 2
	print(sum)
	s2 = ''
	counter = d['L'] // 2
	counter2 = d['L'] - counter
	for i in range(counter):
		s2 = s2 + 'L'
	counter = d['D'] // 2
	counter3 = d['D'] - counter
	for i in range(counter):
		s2 = s2 + 'D'
	for i in range(d['R']):
		s2 = s2 + 'R'
	for i in range(d['U']):
		s2 = s2 + 'U'
	for i in range(counter2):
		s2 = s2 + 'L'
	for i in range(counter3):
		s2 = s2 + 'D'
	return s2
n = int(input(''))
while n > 0:
	s = input('')
	print(f(s))
	n = n - 1


q = int(input())
for x in range(q):
	instr = input()
	hist = [0, 0, 0, 0]
	for c in instr:
		if c == 'U':
			hist[0] += 1
		if c == 'D':
			hist[1] += 1
		if c == 'L':
			hist[2] += 1
		if c == 'R':
			hist[3] += 1
	maxVert = min(hist[0], hist[1])
	maxHori = min(hist[2], hist[3])
	if maxHori == 0 and maxVert != 0:
		print(2)
		print('UD')
	elif maxVert == 0 and maxHori != 0:
		print(2)
		print('LR')
	else:
		print((maxVert + maxHori) * 2)
		for y in range(maxVert):
			print('U', end='')
		for y in range(maxHori):
			print('R', end='')
		for y in range(maxVert):
			print('D', end='')
		for y in range(maxHori):
			print('L', end='')
		print()


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()


t = int(input())
for _ in range(t):
	s = input().strip()
	U = 0
	R = 0
	D = 0
	L = 0
	for c in s:
		if c == 'U':
			U += 1
		elif c == 'R':
			R += 1
		elif c == 'D':
			D += 1
		elif c == 'L':
			L += 1
	min_UD = min(U, D)
	min_RL = min(R, L)
	if min_UD == 0 and min_RL > 1:
		print(2)
		print('RL')
	elif min_UD > 1 and min_RL == 0:
		print(2)
		print('UD')
	else:
		print(2 * (min_UD + min_RL))
		print('U' * min_UD + 'R' * min_RL + 'D' * min_UD + 'L' * min_RL)


t = int(input())
for i in range(t):
	a = input()
	b = [0, 0, 0, 0]
	for j in range(len(a)):
		if a[j] == 'U':
			b[0] = b[0] + 1
		if a[j] == 'D':
			b[1] = b[1] + 1
		if a[j] == 'L':
			b[2] = b[2] + 1
		if a[j] == 'R':
			b[3] = b[3] + 1
	c = min(b[0], b[1])
	b[0] = c
	b[1] = c
	d = min(b[2], b[3])
	b[2] = d
	b[3] = d
	if c == 0 and d != 0:
		print(2)
		print('LR')
	elif c != 0 and d == 0:
		print(2)
		print('UD')
	else:
		c = 'U' * b[0] + 'L' * b[2] + 'D' * b[1] + 'R' * b[3]
		print(len(c))
		print(c)


for i in range(int(input())):
	s = input()
	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 and D > 0):
		print(2)
		print('UD')
		continue
	if (U == 0 or D == 0) and (L > 0 and R > 0):
		print(2)
		print('LR')
		continue
	ans = 'R' * min(R, L) + 'U' * min(U, D) + 'L' * min(R, L) + 'D' * min(U, D)
	print(len(ans))
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	u = s.count('U')
	d = s.count('D')
	l = s.count('L')
	r = s.count('R')
	t1 = min(u, d)
	t2 = min(l, r)
	if t1 != 0 and t2 != 0:
		ans = t1 + t1 + t2 + t2
		st = ''
		if t1 > 0:
			st = st + 'U' * t1
		if t2 > 0:
			st = st + 'L' * t2
		if t1 > 0:
			st = st + 'D' * t1
		if t2 > 0:
			st = st + 'R' * t2
		print(ans)
		print(st)
	elif t1 == 0 and t2 != 0:
		ans = 2
		st = 'LR'
		print(ans)
		print(st)
	elif t1 != 0 and t2 == 0:
		ans = 2
		st = 'UD'
		print(ans)
		print(st)
	else:
		ans = 0
		st = ''
		print(ans)
		print(st)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
from collections import Counter
t = rint()
for _ in range(t):
	c = Counter(input())
	ud = min(c['D'], c['U'])
	lr = min(c['L'], c['R'])
	if ud == 0 or lr == 0:
		ud = min(1, ud)
		lr = min(1, lr)
	print(2 * ud + 2 * lr)
	print('D' * ud + 'L' * lr + 'U' * ud + 'R' * lr)


q = int(input())

def countchar(string):
	r = 0
	l = 0
	u = 0
	d = 0
	for i in string:
		if i == 'R':
			r += 1
		elif i == 'L':
			l += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	return (d, l, r, u)
for i in range(q):
	string = input()
	t = countchar(string)
	MDU = min(t[0], t[3])
	MLR = min(t[1], t[2])
	if MDU > 0 and MLR > 0:
		print((MLR + MDU) * 2)
		print(MDU * 'D' + MLR * 'R' + MDU * 'U' + MLR * 'L')
	elif MDU == 0 and MLR == 0:
		print(0)
	elif MDU == 0 and MLR > 0:
		print(2)
		print('LR')
	elif MLR == 0 and MDU > 0:
		print(2)
		print('UD')


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()


t = int(input())
for i in range(t):
	a = input()
	left = a.count('L')
	right = a.count('R')
	up = a.count('U')
	down = a.count('D')
	if min(left, right) == 0:
		if min(up, down) == 0:
			print(0)
		else:
			print(2)
			print('DU')
	elif min(down, up) == 0:
		print(2)
		print('LR')
	else:
		print(2 * min(left, right) + 2 * min(up, down))
		(print('L' * int(min(left, right)) + 'U' * int(min(up, down)) + 'R' * int(min(left, right)) + 'D' * int(min(up, down))),)


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()


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from collections import defaultdict as dd
(t,) = I()
while t:
	t -= 1
	s = input()
	(u, l, r, d) = (s.count('U'), s.count('L'), s.count('R'), s.count('D'))
	l = min(l, r)
	u = min(u, d)
	if u == 0 and l == 0:
		print(0)
	elif u == 0 and l > 0:
		print(2)
		print('LR')
	elif l == 0 and u > 0:
		print(2)
		print('UD')
	else:
		print(2 * l + 2 * u)
		print('L' * l + 'D' * u + 'R' * l + 'U' * u)


q = int(input())
for i in range(q):
	s = input()
	dic = {'U': 0, 'D': 0, 'R': 0, 'L': 0}
	for ch in s:
		dic[ch] += 1
	up_down = min(dic['U'], dic['D'])
	rigth_left = min(dic['R'], dic['L'])
	if up_down == 0:
		rigth_left = min(rigth_left, 1)
	if rigth_left == 0:
		up_down = min(up_down, 1)
	print(2 * up_down + 2 * rigth_left)
	print('U' * up_down + 'R' * rigth_left + 'D' * up_down + 'L' * rigth_left)


q = int(input())
out = []
for i in range(q):
	s = input()
	a = s.count('L')
	b = s.count('R')
	c = s.count('U')
	d = len(s) - (a + b + c)
	if a == 0 or b == 0:
		if c == 0 or d == 0:
			out.append('0')
		else:
			out.append('UD')
		continue
	if c == 0 or d == 0:
		if a == 0 or b == 0:
			out.append('0')
		else:
			out.append('RL')
		continue
	kq = 'L' * min(a, b) + 'U' * min(c, d) + 'R' * min(a, b) + 'D' * min(c, d)
	out.append(kq)
for i in range(q):
	if out[i] == '0':
		print(out[i])
	else:
		print(len(out[i]))
		print(out[i])


import sys
import collections
from collections import Counter
import itertools
import math
import timeit

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

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

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
t = ii()
res = []
for _ in range(t):
	c = Counter(input())
	ud = min(c['U'], c['D'])
	rl = min(c['R'], c['L'])
	if ud == 0:
		rl = min(rl, 1)
	if rl == 0:
		ud = min(ud, 1)
	r = ud * 'U' + rl * 'R' + ud * 'D' + rl * 'L'
	res.append(len(r))
	res.append(r)
prr(res, '\n')


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)


n = int(input())
num_low = 0
num_mid = 0
min_high = 0
temp_s = []
ls_abc = []
ls_temp = []
ans = 0
goup = 0
gorgt = 0
temp_cell = [0, 0]
ans_s = []
for i in range(n):
	temp_s.append(input())
for i in range(n):
	ans_s = []
	ans = 0
	cntu = 0
	cntd = 0
	cntr = 0
	cntl = 0
	s = temp_s[i]
	cntu = s.count('U')
	cntd = s.count('D')
	cntr = s.count('R')
	cntl = s.count('L')
	goup = min(cntu, cntd)
	gorgt = min(cntr, cntl)
	if goup > 0 and gorgt > 0:
		ans_s.extend(['U'] * goup)
		ans_s.extend(['R'] * gorgt)
		ans_s.extend(['D'] * goup)
		ans_s.extend(['L'] * gorgt)
	elif gorgt > 0:
		ans_s.extend(['L', 'R'])
	elif goup > 0:
		ans_s.extend(['U', 'D'])
	else:
		ans_s = []
	print(len(ans_s))
	print(''.join(ans_s))


for i in range(int(input())):
	g = list(input())
	r = g.count('R')
	l = g.count('L')
	u = g.count('U')
	d = g.count('D')
	if r > l:
		for i in range(r - l):
			g.remove('R')
	if r < l:
		for i in range(l - r):
			g.remove('L')
	if u > d:
		for i in range(u - d):
			g.remove('U')
	if u < d:
		for i in range(d - u):
			g.remove('D')
	if (u == 0 or d == 0) and len(g):
		g = ['R', 'L']
	if (r == 0 or l == 0) and len(g):
		g = ['U', 'D']
	print(len(g))
	print(''.join(sorted(g, key=lambda x: 'M' if x == 'U' else x)))


q = int(input())
for i in range(q):
	cu = 0
	cd = 0
	cl = 0
	cr = 0
	mayc = 0
	maya = 0
	cad = str(input())
	for l in cad:
		if l == 'U':
			cu += 1
		elif l == 'D':
			cd += 1
		elif l == 'L':
			cl += 1
		elif l == 'R':
			cr += 1
	if cu <= cd:
		mayc = cu
	else:
		mayc = cd
	if cl <= cr:
		maya = cl
	else:
		maya = cr
	s = 2 * mayc + 2 * maya
	if mayc > 0 and maya > 0:
		print(s)
		print('U' * mayc + 'L' * maya + 'D' * mayc + 'R' * maya)
	elif mayc > 0:
		print(2)
		print('UD')
	elif maya > 0:
		print(2)
		print('RL')
	else:
		print(0)
		print()


import sys
q = int(input())
while q > 0:
	q -= 1
	s = input()
	(L, R, D, U) = (0, 0, 0, 0)
	for i in range(len(s)):
		if s[i] == 'U':
			U += 1
		elif s[i] == 'D':
			D += 1
		elif s[i] == 'R':
			R += 1
		else:
			L += 1
	if min(U, D) == 0:
		L = R = min(1, min(R, L))
	if min(R, L) == 0:
		U = D = min(1, min(U, D))
	print(min(U, D) * 2 + min(R, L) * 2)
	for i in range(min(U, D)):
		print('U', end='')
	for i in range(min(R, L)):
		print('R', end='')
	for i in range(min(U, D)):
		print('D', end='')
	for i in range(min(R, L)):
		print('L', end='')
	print()


for _ in range(int(input())):
	a = input()
	l = 0
	r = 0
	d = 0
	u = 0
	for i in a:
		if i == 'L':
			l += 1
		if i == 'R':
			r += 1
		if i == 'D':
			d += 1
		if i == 'U':
			u += 1
	ans = min(l, r)
	an = min(u, d)
	if an == 0 and ans != 0:
		print(2)
		print('L' + 'R')
	elif ans == 0 and an != 0:
		print(2)
		print('U' + 'D')
	else:
		n = 2 * ans + 2 * an
		print(n)
		print(ans * 'R' + an * 'U' + ans * 'L' + an * 'D')


t = int(input())

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


N = int(input())
for _ in range(N):
	p = input()
	f = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	for l in p:
		f[l] += 1
	f['U'] = f['D'] = min(f['U'], f['D'])
	f['R'] = f['L'] = min(f['R'], f['L'])
	if f['U'] == 0:
		f['R'] = f['L'] = min(1, f['R'])
	if f['R'] == 0:
		f['U'] = f['D'] = min(1, f['U'])
	print(2 * f['U'] + 2 * f['R'])
	print('U' * f['U'] + 'R' * f['R'] + 'D' * f['D'] + 'L' * f['L'])


from collections import Counter
for _ in range(int(input())):
	s = input()
	x = Counter(s)
	left = 0
	right = 0
	up = 0
	down = 0
	for i in x:
		if i == 'L':
			left = x[i]
		elif i == 'R':
			right = x[i]
		elif i == 'U':
			up = x[i]
		else:
			down = x[i]
	left = min(left, right)
	right = min(left, right)
	up = min(up, down)
	down = min(up, down)
	length = 2 * left + 2 * up
	strr = ''
	for i in range(right // 2):
		strr += 'R'
	right -= right // 2
	for i in range(up):
		strr += 'U'
	for i in range(left):
		strr += 'L'
	for i in range(down):
		strr += 'D'
	for i in range(right):
		strr += 'R'
	if up == 0 and left == 0:
		print(0)
		print('')
	elif up == 0:
		print(2)
		print('LR')
	elif left == 0:
		print(2)
		print('UD')
	else:
		print(length)
		print(strr)


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)


ans1 = []
ans2 = []
for _ in range(int(input())):
	str1 = input()
	u = str1.count('U')
	d = str1.count('D')
	l = str1.count('L')
	r = str1.count('R')
	ud = 0
	lr = 0
	if u > d:
		ud = d
	else:
		ud = u
	if l > r:
		lr = r
	else:
		lr = l
	if lr == 0 and ud != 0:
		ud = 1
	if ud == 0 and lr != 0:
		lr = 1
	ans1.append(ud * 2 + lr * 2)
	ans2.append('U' * ud + 'R' * lr + 'D' * ud + 'L' * lr)
for i in range(len(ans1)):
	print(ans1[i])
	print(ans2[i])


for i in range(int(input())):
	s = list(input())
	a = s.count('R')
	b = s.count('L')
	c = s.count('U')
	d = s.count('D')
	k = min(a, b)
	y = min(c, d)
	s = 0
	t = 2 * (min(a, b) + min(c, d))
	if (a == 0 or b == 0) and (c != 0 and d != 0):
		print(2)
		print('U' * 1 + 'D' * 1)
	if (d == 0 or c == 0) and (a != 0 and b != 0):
		print(2)
		print('L' * 1 + 'R' * 1)
	if a == 0 and b == 0 and (c == 0) or (a == 0 and b == 0 and (d == 0)) or (b == 0 and c == 0 and (d == 0)) or (a == 0 and c == 0 and (d == 0)) or (a == 0 and c == 0 or (a == 0 and d == 0)) or (b == 0 and d == 0 or (b == 0 and c == 0)) or (a == 0 and b == 0 and (c == 0) and (d == 0)):
		print(0)
		print()
	if a != 0 and b != 0 and (c != 0) and (d != 0):
		print(int(2 * (k + y)))
		print('U' * y + 'R' * k + 'D' * y + 'L' * k)


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)


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : list(input())
t = ii()
for _ in range(t):
	n = ip()
	d = defaultdict(int)
	for i in n:
		d[i] += 1
	a = min(d['U'], d['D'])
	b = min(d['L'], d['R'])
	ans = ''
	if b == 0 and a > 0:
		a = 1
	elif a == 0 and b > 0:
		b = 1
	for i in range(a):
		ans += 'U'
	for i in range(b):
		ans += 'L'
	for i in range(a + b):
		if ans[i] == 'U':
			ans += 'D'
		else:
			ans += 'R'
	print(len(ans))
	print(ans)


for q in range(int(input())):
	s = input()
	d = dict()
	d['L'] = 0
	d['R'] = 0
	d['U'] = 0
	d['D'] = 0
	for i in s:
		d[i] += 1
	if d['L'] != d['R']:
		d['L'] = min(d['L'], d['R'])
		d['R'] = d['L']
	if d['U'] != d['D']:
		d['U'] = min(d['U'], d['D'])
		d['D'] = d['U']
	if d['U'] == 0:
		if d['L']:
			print(2)
			print('LR')
		else:
			print(0)
			print()
	elif d['L'] == 0:
		if d['U']:
			print(2)
			print('UD')
		else:
			print(0)
			print()
	else:
		ans = 'L' * d['L'] + 'D' * d['D'] + 'R' * d['R'] + 'U' * d['U']
		print(len(ans))
		print(ans)


import sys
from collections import Counter
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
q = int(input())
for _ in range(q):
	s = input()
	ctr = Counter(s)
	ctr['R'] = ctr['L'] = min(ctr['R'], ctr['L'])
	ctr['U'] = ctr['D'] = min(ctr['U'], ctr['D'])
	if ctr['R'] == 0 and ctr['U'] == 0:
		print(0)
	elif ctr['R'] == 0:
		print(2)
		print('UD')
	elif ctr['U'] == 0:
		print(2)
		print('LR')
	else:
		print(2 * (ctr['R'] + ctr['U']))
		print('R' * ctr['R'] + 'U' * ctr['U'] + 'L' * ctr['L'] + 'D' * ctr['D'])


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 collections import Counter
for _ in range(int(input())):
	a = input()
	count = Counter(a)
	maxlength = abs(count['L'] - count['R']) + abs(count['U'] - count['D'])
	if count['U'] != 0 and count['D'] != 0 and (count['L'] != 0) and (count['R'] != 0):
		print(len(a) - maxlength)
		if count['L'] > count['R']:
			for _ in range(count['R']):
				(print('L', end=''),)
		else:
			for _ in range(count['L']):
				(print('L', end=''),)
		if count['U'] > count['D']:
			for _ in range(count['D']):
				(print('U', end=''),)
		else:
			for _ in range(count['U']):
				(print('U', end=''),)
		if count['L'] > count['R']:
			for _ in range(count['R']):
				(print('R', end=''),)
		else:
			for _ in range(count['L']):
				(print('R', end=''),)
		if count['U'] > count['D']:
			for _ in range(count['D']):
				(print('D', end=''),)
		else:
			for _ in range(count['U']):
				(print('D', end=''),)
		print('\n')
	elif (count['U'] == 0 or count['D'] == 0) and (count['L'] != 0 and count['R'] != 0):
		print('2')
		print('LR')
	elif (count['L'] == 0 or count['R'] == 0) and (count['U'] != 0 and count['D'] != 0):
		print('2')
		print('UD')
	else:
		print('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)


t = int(input())
while t:
	t -= 1
	a = input()
	f1 = [a.count('D'), a.count('U')]
	f2 = [a.count('R'), a.count('L')]
	x1 = min(f1)
	x2 = min(f2)
	if x1 == 0 and x2 != 0:
		print(2)
		print('RL')
		continue
	elif x2 == 0 and x1 != 0:
		print(2)
		print('UD')
		continue
	elif x1 == x2 == 0:
		print(0)
		print()
		continue
	print(2 * (x1 + x2))
	print('U' * x1 + 'R' * x2 + 'D' * x1 + 'L' * x2)


for _ in range(int(input())):
	s = input()
	lis = [0] * 4
	for i in s:
		if i == 'U':
			lis[0] += 1
		elif i == 'R':
			lis[2] += 1
		elif i == 'D':
			lis[1] += 1
		else:
			lis[3] += 1
	if lis[0] > lis[1]:
		lis[0] = lis[1]
	else:
		lis[1] = lis[0]
	if lis[2] > lis[3]:
		lis[2] = lis[3]
	else:
		lis[3] = lis[2]
	if lis[0] == 0:
		lis[2] = min(1, lis[2])
		lis[3] = min(1, lis[3])
	if lis[3] == 0:
		lis[0] = min(1, lis[0])
		lis[1] = min(1, lis[1])
	print(sum(lis))
	print('U' * lis[0] + 'R' * lis[2] + 'D' * lis[1] + 'L' * lis[3])


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 = ''


for _ in [0] * int(input()):
	(u, v, *x) = map(input().count, 'LRUD')
	a = min(u, v)
	b = min(x)
	if b < 1:
		a = a and 1
	elif a < 1:
		b = 1
	print(2 * (a + b), 'L' * a + 'U' * b + 'R' * a + 'D' * b)


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)


from collections import Counter
t = int(input())
for _ in range(t):
	s = list(input())
	d = Counter(s)
	lr = min(d['L'], d['R'])
	ud = min(d['U'], d['D'])
	if lr == 0 and ud > 1:
		print('2')
		print('DU')
		continue
	if ud == 0 and lr > 1:
		print(2)
		print('RL')
		continue
	print(2 * lr + 2 * ud)
	a = ['R'] * lr + ['D'] * ud + ['L'] * lr + ['U'] * ud
	if a != []:
		print(''.join(a))


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


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


from sys import stdin, stdout
from collections import Counter
for _ in range(int(stdin.readline())):
	s = input()
	n = len(s)
	d = Counter(s)
	u = d['U']
	l = d['L']
	r = d['R']
	d = d['D']
	if u > 0 and l > 0 and (r > 0) and (d > 0):
		ans = 'U' * min(u, d) + 'L' * min(l, r) + 'D' * min(u, d) + 'R' * min(l, r)
	elif u * l * r * d == 0:
		ans = 'LR' * int(l > 0 and r > 0) + 'UD' * int(u > 0 and d > 0)
	print(len(ans))
	print(ans)


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('')


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


def main():
	string = list(str(input()))
	d = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for i in range(len(string)):
		d[string[i]] += 1
	res = ''
	if min(d['U'], d['D']) == 0 or min(d['L'], d['R']) == 0:
		if min(d['U'], d['D']) == 0:
			if min(d['L'], d['R']) != 0:
				d['L'] = 1
		elif min(d['L'], d['R']) == 0:
			d['U'] = 1
	print(2 * min(d['D'], d['U']) + 2 * min(d['L'], d['R']))
	res += 'D' * min(d['D'], d['U'])
	res += 'L' * min(d['L'], d['R'])
	res += 'U' * min(d['D'], d['U'])
	res += 'R' * min(d['L'], d['R'])
	print(res)
t = int(input())
while t:
	main()
	t -= 1


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))


for _ in range(int(input())):
	s = input()
	u = s.count('U')
	l = s.count('L')
	r = s.count('R')
	d = s.count('D')
	ver = min(u, d)
	hor = min(l, r)
	a = []
	if min(hor, ver) == 0:
		if hor == 0:
			if min(ver, 1) == 0:
				print(0)
				print('')
			else:
				print(2)
				print('UD')
		elif min(hor, 1) == 0:
			print(0)
			print('')
		else:
			print(2)
			print('LR')
	else:
		for i in range(ver):
			a.append('U')
		for i in range(hor):
			a.append('R')
		for i in range(ver):
			a.append('D')
		for i in range(hor):
			a.append('L')
		print(len(a))
		print(*a, sep='')


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)))


for _ in range(int(input())):
	str = input()
	dic = {'U': 0, 'D': 0, 'R': 0, 'L': 0}
	for i in str:
		if i in dic:
			dic[i] += 1
	if dic['L'] != dic['R']:
		dic['L'] = dic['R'] = min(dic['L'], dic['R'])
	if dic['U'] != dic['D']:
		dic['U'] = dic['D'] = min(dic['U'], dic['D'])
	count = 0
	for i in dic:
		count += dic[i]
	s = ''
	if dic['D'] != 0 and dic['R'] != 0:
		s = 'D' * dic['D'] + 'R' * dic['R'] + 'U' * dic['U'] + 'L' * dic['L']
	elif dic['D'] == 0 and dic['L'] != 0:
		s = 'LR'
	elif dic['L'] == 0 and dic['D'] != 0:
		s = 'UD'
	print(len(s))
	print(s)


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 i2 in range(q):
	s = input()
	L = s.count('L')
	R = s.count('R')
	D = s.count('D')
	U = s.count('U')
	if min(L, R) == 0 and min(D, U) == 0:
		print(0)
		continue
	elif min(D, U) == 0:
		print(2)
		print('LR')
		continue
	elif min(L, R) == 0:
		print(2)
		print('DU')
		continue
	res = (min(L, R) + min(D, U)) * 2
	resm = ['L' for i in range(min(L, R))]
	resm += ['D' for i3 in range(min(D, U))]
	resm += ['R' for i4 in range(min(R, L))]
	resm += ['U' for i5 in range(min(U, D))]
	print(res)
	print(*resm, sep='')


t = int(input())
while t > 0:
	s = input()
	l = 0
	r = 0
	u = 0
	d = 0
	for values in s:
		if values == 'L':
			l += 1
		if values == 'R':
			r += 1
		if values == 'U':
			u += 1
		if values == 'D':
			d += 1
	ans = 0
	if r >= l:
		ans += 2 * l
		r = l
	else:
		ans += 2 * r
		l = r
	if d >= u:
		ans += 2 * u
		d = u
	else:
		ans += 2 * d
		u = d
	res = ''
	if r == 0:
		if u >= 1:
			print(2)
			print('UD')
		else:
			print(0)
			print('')
	elif u == 0:
		if r >= 1:
			print(2)
			print('LR')
		else:
			print(0)
			print('')
	else:
		print(ans)
		while r > 0:
			res += 'R'
			r -= 1
		while u > 0:
			res += 'U'
			u -= 1
		while l > 0:
			res += 'L'
			l -= 1
		while d > 0:
			res += 'D'
			d -= 1
		print(res)
	t -= 1


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 defaultdict

def find(x):
	dic = defaultdict(int)
	for i in x:
		dic[i] += 1
	one = min(dic['R'], dic['L'])
	two = min(dic['U'], dic['D'])
	ans = one + one + two + two
	s = 'R' * one + 'D' * two + 'L' * one + 'U' * two
	if two == 0 and one != 0:
		ans = 2
		s = 'LR'
	if one == 0 and two != 0:
		ans = 2
		s = 'UD'
	return (ans, s)
for i in range(int(input())):
	x = input()
	ans = find(x)
	print(ans[0])
	print(ans[1])


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())):
	seq = input()
	left = seq.count('L')
	right = seq.count('R')
	up = seq.count('U')
	down = seq.count('D')
	if left != right:
		left = min(left, right)
		right = left
	if up != down:
		up = min(up, down)
		down = up
	if left == 0 and up > 0:
		print(2)
		print('UD')
	elif left > 0 and up == 0:
		print(2)
		print('LR')
	else:
		res = 'U' * up + 'R' * right + 'D' * down + 'L' * left
		print(len(res))
		print(res)


n = int(input())
for i in range(n):
	s = input()
	l = 0
	u = 0
	r = 0
	d = 0
	for j in range(len(s)):
		if s[j] == 'D':
			d += 1
		elif s[j] == 'L':
			l += 1
		elif s[j] == 'U':
			u += 1
		else:
			r += 1
	c = min(l, r) + min(u, d)
	c *= 2
	if min(u, d) == 0:
		c = 2
		s = 'LR'
	elif min(l, r) == 0:
		c = 2
		s = 'UD'
	else:
		s = ''
		for k in range(min(l, r)):
			s = s + 'L'
		for k in range(min(u, d)):
			s = s + 'D'
		for k in range(min(l, r)):
			s = s + 'R'
		for k in range(min(u, d)):
			s = s + 'U'
	if min(l, r) == 0 and min(u, d) == 0:
		c = 0
		s = ''
	print(c)
	print(s)


t = int(input())
for _ in range(t):
	s = list(input())
	count = [0 for j in range(4)]
	for j in range(len(s)):
		if s[j] == 'U':
			count[0] += 1
		elif s[j] == 'D':
			count[1] += 1
		elif s[j] == 'L':
			count[2] += 1
		else:
			count[3] += 1
	vala = min(count[0], count[1])
	valb = min(count[3], count[2])
	if vala == 0 and valb == 0:
		print(0)
	elif vala == 0:
		print(2)
		print('LR')
	elif valb == 0:
		print(2)
		print('UD')
	else:
		print(2 * vala + 2 * valb)
		print('R' * valb + 'D' * vala + 'L' * valb + 'U' * vala)


from collections import defaultdict
t = int(input())
while t:
	t -= 1
	s = input()
	cnt = defaultdict(int)
	for c in s:
		cnt[c] += 1
	a = 0
	if cnt['U'] == cnt['D']:
		a = cnt['U']
	else:
		a = min(cnt['U'], cnt['D'])
	b = 0
	if cnt['R'] == cnt['L']:
		b = cnt['L']
	else:
		b = min(cnt['R'], cnt['L'])
	if a == 0 and b != 0:
		print(2)
		print('LR')
	elif b == 0 and a != 0:
		print(2)
		print('UD')
	else:
		print(a * 2 + b * 2)
		for i in range(a):
			print('U', end='')
		for i in range(b):
			print('R', end='')
		for i in range(a):
			print('D', end='')
		for i in range(b):
			print('L', end='')
		print()


t = int(input())
for _ in range(t):
	inp = input()
	numU = inp.count('U')
	numD = inp.count('D')
	numL = inp.count('L')
	numR = inp.count('R')
	minU = 0
	minL = 0
	minR = 0
	minD = 0
	if numU != numD:
		z = min((numU, numD))
		minU = z
		minD = z
	else:
		minU = numU
		minD = numD
	if numL != numR:
		z = min((numL, numR))
		minL = z
		minR = z
	else:
		minL = numL
		minR = numR
	if minU == 0:
		minL = min((1, minL))
		minR = min((1, minR))
	if minL == 0:
		minU = min((1, minU))
		minD = min((1, minD))
	o = '' + 'U' * minU + 'L' * minL + 'D' * minD + 'R' * minR
	print(minU + minL + minD + minR)
	print(o)


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


q = int(input().strip())
for i in range(q):
	path = list(input().strip())
	left = path.count('L')
	right = path.count('R')
	down = path.count('D')
	up = path.count('U')
	h = min(left, right)
	v = min(up, down)
	if h * v == 0 and max(h, v) == 0:
		print(0)
	elif h * v == 0:
		print(2)
		if h == 0:
			print('UD')
		else:
			print('RL')
	else:
		print(2 * (h + v))
		print('R' * h + 'U' * v + 'L' * h + 'D' * v)


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)


t = int(input())
for i in range(t):
	s = input()
	lctr = s.count('L')
	uctr = s.count('U')
	dctr = s.count('D')
	rctr = s.count('R')
	lr = min(lctr, rctr)
	ud = min(uctr, dctr)
	if lr == 0 and ud != 0:
		print(2)
		print('UD')
	elif lr != 0 and ud == 0:
		print(2)
		print('LR')
	else:
		ans = ''
		ans += 'R' * lr
		ans += 'U' * ud
		ans += 'L' * lr
		ans += 'D' * ud
		print(len(ans))
		if len(ans) != 0:
			print(ans)


q = int(input())
for i in range(q):
	inp = input()
	nU = 0
	nD = 0
	nR = 0
	nL = 0
	for c in inp:
		if c == 'U':
			nU = nU + 1
		elif c == 'D':
			nD = nD + 1
		elif c == 'L':
			nL = nL + 1
		elif c == 'R':
			nR = nR + 1
	nU = min(nU, nD)
	nR = min(nR, nL)
	if nU != 0 and nR != 0:
		print(2 * (nR + nU))
		str1 = 'U' * nU + 'R' * nR + 'D' * nU + 'L' * nR
		print(str1)
	elif nU == 0 and nR == 0:
		print(0)
	elif nU != 0 and nR == 0:
		print(2)
		print('UD')
	else:
		print(2)
		print('LR')


t = int(input())
for _ in range(t):
	s = input()
	(r, l, u, d) = [s.count('R'), s.count('L'), s.count('U'), s.count('D')]
	h = min(r, l)
	v = min(u, d)
	ans = ''
	if h == 0 and v != 0:
		ans = 'UD'
	elif h != 0 and v == 0:
		ans = 'LR'
	else:
		ans = 'R' * h + 'U' * v + 'L' * h + 'D' * v
	print(len(ans))
	print(ans)


q = int(input())
for w in range(q):
	s = str(input())
	n = len(s)
	(x, y) = (0, 0)
	ans = ''
	was = []
	if n == 1:
		print(0)
		continue
	sCheck = list(set(s))
	if len(sCheck) == 1:
		print(0)
		continue
	if len(sCheck) == 2 and ((sCheck[0] == 'U' and sCheck[1] == 'D' or (sCheck[1] == 'U' and sCheck[0] == 'D')) or (sCheck[1] == 'R' and sCheck[0] == 'L' or (sCheck[0] == 'R' and sCheck[1] == 'L'))):
		print(2)
		print(str(sCheck[0]) + str(sCheck[1]))
		continue
	countL = 0
	countR = 0
	countD = 0
	countU = 0
	for i in range(n):
		if s[i] == 'L':
			countL += 1
		elif s[i] == 'R':
			countR += 1
		elif s[i] == 'U':
			countU += 1
		else:
			countD += 1
	minLR = min(countL, countR)
	minUD = min(countU, countD)
	if minLR == 0 and minUD == 0:
		print(0)
		continue
	if minLR == 0:
		print(2)
		print('UD')
		continue
	if minUD == 0:
		print(2)
		print('LR')
		continue
	for i in range(minUD):
		ans += 'U'
		y += 1
	for i in range(minLR):
		ans += 'L'
		x += 1
	for i in range(minUD):
		ans += 'D'
		y -= 1
	for i in range(minLR):
		ans += 'R'
		x -= 1
	if x == 0 and y == 0:
		print(len(ans))
		for i in range(len(ans)):
			print(ans[i], end='')
		print()
	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')


from collections import Counter
N = int(input())
for i in range(N):
	a = list(input())
	s = Counter(a)
	u = s['U']
	d = s['D']
	l = s['L']
	r = s['R']
	ans = min(u, d) * 'U' + min(l, r) * 'L' + min(u, d) * 'D' + min(l, r) * 'R'
	if min(u, d) == 0 and min(l, r) >= 1:
		ans = 'LR'
	elif min(u, d) >= 1 and min(l, r) == 0:
		ans = 'UD'
	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()):
	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))


q = int(input())
for _ in range(q):
	s = input()
	uc = s.count('U')
	dc = s.count('D')
	lc = s.count('L')
	rc = s.count('R')
	fmin = min(uc, dc)
	smin = min(lc, rc)
	ans = 2 * (fmin + smin)
	if fmin == 0 and smin == 0:
		ans = 0
	elif fmin == 0 or smin == 0:
		ans = 2
	print(ans)
	a_str = ''
	if fmin == 0 and smin == 0:
		a_str = ''
	elif fmin == 0:
		a_str = 'LR'
	elif smin == 0:
		a_str = 'UD'
	else:
		a_str = 'U' * fmin + 'R' * smin + 'D' * fmin + 'L' * smin
	print(a_str)


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()
	u = s.count('U')
	d = s.count('D')
	l = s.count('L')
	r = s.count('R')
	if u > d:
		u = d
	else:
		d = u
	if r > l:
		r = l
	else:
		l = r
	if u == 0 and r > 1:
		r = l = 1
	if r == 0 and u > 1:
		u = d = 1
	new_str = 'U' * u + 'R' * r + 'D' * d + 'L' * l
	print(len(new_str))
	print(new_str)


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)


for _ in range(int(input())):
	d = input()
	countU = 0
	countD = 0
	countR = 0
	countL = 0
	for i in d:
		if i == 'U':
			countU += 1
		elif i == 'D':
			countD += 1
		elif i == 'R':
			countR += 1
		elif i == 'L':
			countL += 1
	min1 = min(countU, countD)
	min2 = min(countR, countL)
	if min1 == 0 and min2 == 0:
		print(0)
	elif min1 == 0:
		print(2)
		print('LR')
	elif min2 == 0:
		print(2)
		print('UD')
	else:
		U = 'U' * min1
		D = 'D' * min1
		L = 'L' * min2
		R = 'R' * min2
		print(2 * min1 + 2 * min2)
		f = U + L + D + R
		print(f)


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


k = int(input())
for j in range(k):
	s = str(input())
	l = 0
	r = 0
	u = 0
	d = 0
	for i in range(len(s)):
		if s[i] == 'L':
			l += 1
		if s[i] == 'R':
			r += 1
		if s[i] == 'U':
			u += 1
		if s[i] == 'D':
			d += 1
	if (l == 0 or r == 0) and (u == 0 or d == 0):
		print(0, end='')
	elif l == 0 or r == 0:
		print(2)
		print('UD', end='')
	elif u == 0 or d == 0:
		print(2)
		print('RL', end='')
	else:
		print(2 * min(l, r) + 2 * min(d, u))
		print('U' * min(d, u), end='')
		print('R' * min(l, r), end='')
		print('D' * min(d, u), end='')
		print('L' * min(l, r), end='')
	print()


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)


def solve():
	S = input()
	d = {c: 0 for c in 'UDLR'}
	for c in S:
		d[c] += 1
	UD = min(d['U'], d['D'])
	LR = min(d['L'], d['R'])
	if UD > 0 and LR > 0 or (UD == 0 and LR == 0):
		print(2 * (UD + LR))
		print(UD * 'D' + LR * 'L' + UD * 'U' + LR * 'R')
		return
	elif UD == 0:
		print(2)
		print('LR')
	else:
		print(2)
		print('UD')
t = int(input())
for _ in range(t):
	solve()


q = int(input())
j = 1
while j <= q:
	inp = input()
	right = 0
	left = 0
	up = 0
	down = 0
	for i in inp:
		if i == 'R':
			right += 1
		if i == 'L':
			left += 1
		if i == 'U':
			up += 1
		if i == 'D':
			down += 1
	right = min(left, right)
	left = min(left, right)
	up = min(up, down)
	down = min(up, down)
	if right == 0:
		up = min(up, 1)
		down = up
	if up == 0:
		right = min(right, 1)
		left = right
	ans = ''
	for i in range(right):
		ans += 'R'
	for i in range(up):
		ans += 'U'
	for i in range(left):
		ans += 'L'
	for i in range(down):
		ans += 'D'
	print(right + left + up + down)
	print(ans)
	j += 1


N = int(input())
for _ in range(N):
	nums = list(input())
	l = 0
	r = 0
	u = 0
	d = 0
	ln = len(nums)
	for i in range(ln):
		if nums[i] == 'L':
			l += 1
		if nums[i] == 'R':
			r += 1
		if nums[i] == 'U':
			u += 1
		if nums[i] == 'D':
			d += 1
	l = min(l, r)
	u = min(u, d)
	if l > 0 and u > 0:
		a = ['D'] * u
		b = ['U'] * u
		c = ['L'] * l
		d = ['R'] * l
		ans = b + c + a + d
		ans = ''.join(ans)
		print(len(ans))
		print(ans)
	elif l > 0:
		print(2)
		print('LR')
	elif u > 0:
		print(2)
		print('UD')
	else:
		print(0)
		print()


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

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

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

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()
for _ in range(inp()):
	s = input()
	cnt = Counter(s)
	miud = min(cnt['U'], cnt['D'])
	milr = min(cnt['L'], cnt['R'])
	res = []
	if miud == 0 and milr == 0:
		pass
	elif miud == 0:
		res.append('R')
		res.append('L')
	elif milr == 0:
		res.append('U')
		res.append('D')
	else:
		for _ in range(miud):
			res.append('U')
		for _ in range(milr):
			res.append('L')
		for _ in range(miud):
			res.append('D')
		for _ in range(milr):
			res.append('R')
	print(len(res))
	print(''.join(res))


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


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


amt = int(input())
initWalk = []
for i in range(amt):
	snglwalk = input()
	initWalk.append(snglwalk)
for i in initWalk:
	lcount = i.count('L')
	rcount = i.count('R')
	ucount = i.count('U')
	dcount = i.count('D')
	lcount = rcount = min(lcount, rcount)
	ucount = dcount = min(ucount, dcount)
	ans = ''
	if ucount == 0 and lcount > 0:
		lcount = rcount = 1
	if ucount > 0 and lcount == 0:
		ucount = dcount = 1
	for i in range(ucount):
		ans += 'U'
	for i in range(rcount):
		ans += 'R'
	for i in range(dcount):
		ans += 'D'
	for i in range(lcount):
		ans += 'L'
	print(len(ans))
	print(ans)


t = int(input())
for tc in range(t):
	coors = {}
	s = input().rstrip()
	ups = s.count('U')
	downs = s.count('D')
	rights = s.count('R')
	lefts = s.count('L')
	sq = min(ups, downs, rights, lefts)
	res1 = 'R' * sq + 'U' * sq + 'L' * sq + 'D' * sq
	sq2 = min(ups, downs)
	res2a = 'U' * sq2
	res2b = 'D' * sq2
	sq3 = min(rights, lefts)
	res3a = 'R' * sq3
	res3b = 'L' * sq3
	if sq2 == 0 and sq3 > 0:
		print(2)
		print('RL')
		continue
	elif sq3 == 0 and sq2 > 0:
		print(2)
		print('UD')
		continue
	res = res3a + res2a + res3b + res2b
	print(len(res))
	print(res)


for _ in range(int(input())):
	d = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for i in input():
		d[i] += 1
	(l, u) = (min(d['L'], d['R']), min(d['U'], d['D']))
	if l == u == 0:
		print(0)
	elif l == 0:
		print(2, '\n', 'UD', sep='')
	elif u == 0:
		print(2, '\n', 'RL', sep='')
	else:
		print(2 * l + 2 * u, '\n', 'U' * u + 'R' * l + 'D' * u + 'L' * l, sep='')


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()


q = int(input())
for _ in range(q):
	s = list(input())
	ud = min(s.count('U'), s.count('D'))
	lr = min(s.count('L'), s.count('R'))
	if lr == 0:
		ud = min(ud, 1)
	if ud == 0:
		lr = min(lr, 1)
	moves = []
	for _ in range(ud):
		moves.append('U')
	for _ in range(lr):
		moves.append('R')
	for _ in range(ud):
		moves.append('D')
	for _ in range(lr):
		moves.append('L')
	print(len(moves))
	print(''.join(moves))


I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	s = input()
	(a, b, c, d) = (0, 0, 0, 0)
	for i in s:
		if i == 'L':
			a += 1
		elif i == 'R':
			b += 1
		elif i == 'U':
			c += 1
		else:
			d += 1
	a = min(a, b)
	b = min(c, d)
	if b > 0 and a > 0:
		ans = a * 2 + b * 2
		print(ans)
		print('U' * b + 'R' * a + 'D' * b + 'L' * a)
	elif a == 0 and b > 0:
		print(2)
		print('UD')
	elif b == 0 and a > 0:
		print(2)
		print('LR')
	else:
		print(0)


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()


q = int(input())
for _ in range(q):
	s = list(input())
	l = s.count('L')
	r = s.count('R')
	d = s.count('D')
	u = s.count('U')
	d_u = min(d, u)
	r_l = min(r, l)
	if d_u == 0 and r_l == 0:
		print(0)
		continue
	if d_u == 0:
		print(2)
		print('LR')
		continue
	if r_l == 0:
		print(2)
		print('DU')
		continue
	ans = 'D' * d_u + 'R' * r_l + 'U' * d_u + 'L' * r_l
	print(len(ans))
	print(ans)


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)


n = int(input())
for i in range(n):
	s = input()
	(l, r, u, d) = (0, 0, 0, 0)
	for c in s:
		if c == 'L':
			l += 1
		if c == 'R':
			r += 1
		if c == 'U':
			u += 1
		if c == 'D':
			d += 1
	x = min(l, r)
	y = min(u, d)
	if x == 0 and y == 0:
		print(0, end='\n\n')
	elif x == 0:
		print('2\nUD')
	elif y == 0:
		print('2\nLR')
	else:
		print(2 * (x + y))
		for j in range(x):
			print('R', end='')
		for j in range(y):
			print('U', end='')
		for j in range(x):
			print('L', end='')
		for j in range(y):
			print('D', end='')
		print()


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)


import sys
import math
import re
import io

def query_maximum_rectangle(d):
	dx = min(d['L'], d['R'])
	dy = min(d['U'], d['D'])
	if dx == 0 or dy == 0:
		return ''
	t = []
	for i in range(dx):
		t.append('L')
	for i in range(dy):
		t.append('U')
	for i in range(dx):
		t.append('R')
	for i in range(dy):
		t.append('D')
	return ''.join(t)

def query_maximum_y_path(d):
	if d['U'] > 0 and d['D'] > 0:
		return 'DU'
	return ''

def query_maximum_x_path(d):
	if d['R'] > 0 and d['L'] > 0:
		return 'LR'
	return ''

def solve(s):
	d = dict()
	d['L'] = 0
	d['R'] = 0
	d['U'] = 0
	d['D'] = 0
	for c in s:
		if c not in d:
			d[c] = 0
		d[c] += 1
	max_val = -1
	sol = None
	t = query_maximum_rectangle(d)
	if len(t) > max_val:
		max_val = len(t)
		sol = t
	t = query_maximum_y_path(d)
	if len(t) > max_val:
		max_val = len(t)
		sol = t
	t = query_maximum_x_path(d)
	if len(t) > max_val:
		max_val = len(t)
		sol = t
	print(max_val)
	print(sol)

def main():
	for _ in range(int(input())):
		solve(input())
main()


from sys import stdin

def input():
	return int(stdin.readline())

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

def linput():
	return list(map(int, stdin.readline().split()))
for _ in range(input()):
	path = stdin.readline()
	pd = {'U': 0, 'D': 0, 'R': 0, 'L': 0}
	for c in path:
		if c == 'U':
			pd['U'] += 1
		if c == 'D':
			pd['D'] += 1
		if c == 'R':
			pd['R'] += 1
		if c == 'L':
			pd['L'] += 1
	min_v = min(pd['U'], pd['D'])
	min_h = min(pd['R'], pd['L'])
	if min(min_v, min_h) == 0:
		min_v = min(min_v, 1)
		min_h = min(min_h, 1)
	print((min_h + min_v) * 2)
	for c in range(2):
		for i in range(min_v):
			if c == 0:
				print('U', end='')
			else:
				print('D', end='')
		for i in range(min_h):
			if c == 0:
				print('R', end='')
			else:
				print('L', end='')
	print()


q = int(input())
for qq in range(q):
	u = d = l = r = 0
	for c in input().strip():
		if c == 'L':
			l += 1
		elif c == 'D':
			d += 1
		elif c == 'U':
			u += 1
		else:
			r += 1
	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)
	print(u + d + l + r)
	print('U' * u + 'L' * l + 'D' * d + 'R' * r)


for i in range(int(input())):
	s = input()
	d = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	for i in s:
		d[i] += 1
	cnt = max(d['U'], d['D']) - min(d['U'], d['D'])
	cnt += max(d['L'], d['R']) - min(d['L'], d['R'])
	if min(d['U'], d['D']) and min(d['L'], d['R']):
		print(len(s) - cnt)
		print('R' * min(d['L'], d['R']) + 'U' * min(d['U'], d['D']) + 'L' * min(d['L'], d['R']) + 'D' * min(d['U'], d['D']))
	elif len(s) == 1 or (min(d['L'], d['R']) == 0 and min(d['U'], d['D']) == 0):
		print(0)
	else:
		cnt = len(s) - 2
		print(len(s) - cnt)
		if min(d['L'], d['R']) == 0:
			print('U' + 'D')
		else:
			print('L' + 'R')


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
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 defaultdict
t = int(input())
while t:
	d = defaultdict(int)
	s = input()
	for i in s:
		d[i] += 1
	if len(d) == 1:
		print(0)
		print()
		t = t - 1
		continue
	lr = max(d['R'], d['L']) - abs(d['R'] - d['L'])
	ud = max(d['U'], d['D']) - abs(d['U'] - d['D'])
	ans = []
	if d['U'] != 0 and d['R'] != 0 and (d['L'] == 0) and (d['D'] == 0):
		print(0)
		print()
	elif d['U'] != 0 and d['L'] != 0 and (d['R'] == 0) and (d['D'] == 0):
		print(0)
		print()
	elif d['D'] != 0 and d['L'] != 0 and (d['R'] == 0) and (d['U'] == 0):
		print(0)
		print()
	elif d['D'] != 0 and d['R'] != 0 and (d['L'] == 0) and (d['U'] == 0):
		print(0)
		print()
	elif d['U'] == 0 and d['D'] == 0 or ud == 0:
		print(2)
		print('LR')
	elif d['L'] == 0 and d['R'] == 0 or lr == 0:
		print(2)
		print('UD')
	else:
		for i in range(lr):
			ans.append('R')
		for i in range(ud):
			ans.append('U')
		for i in range(lr):
			ans.append('L')
		for i in range(ud):
			ans.append('D')
		print(len(ans))
		print(''.join(ans))
	t = t - 1


q = int(input())
for test in range(0, q):
	s = str(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('0')
	elif x == 0:
		print('2')
		print('UD')
	elif y == 0:
		print('2')
		print('LR')
	else:
		print(str(2 * x + 2 * y))
		ans = ''
		for i in range(0, y):
			ans += 'U'
		for i in range(0, x):
			ans += 'R'
		for i in range(0, y):
			ans += 'D'
		for i in range(0, x):
			ans += 'L'
		print(ans)


for _ in range(int(input())):
	a = input()
	l = a.count('L')
	r = a.count('R')
	d = a.count('D')
	u = a.count('U')
	if len(a) < 2 or [l, r, d, u].count(0) == 3:
		print(0)
		continue
	v = min(d, u)
	h = min(l, r)
	if v == 0 and h != 0 or (v != 0 and h == 0):
		if h != 0:
			print(2)
			print('LR')
		else:
			print(2)
			print('DU')
	else:
		print(2 * v + 2 * h)
		print('L' * h + 'D' * v + 'R' * h + 'U' * v)


test = int(input())
for i in range(test):
	s = input()
	l = 0
	r = 0
	u = 0
	d = 0
	n = len(s)
	if n == 0:
		print(0)
		print('')
		continue
	for i in range(n):
		if s[i] == 'L':
			l += 1
		if s[i] == 'D':
			d += 1
		if s[i] == 'U':
			u += 1
		if s[i] == 'R':
			r += 1
	h = min(l, r)
	v = min(u, d)
	FLAG = 0
	if h == 0 or v == 0:
		FLAG = 1
		delta = min(2 * h + 2 * v, 2)
		print(delta)
	else:
		print(2 * h + 2 * v)
	ans = ''
	if FLAG == 1:
		if delta == 0:
			print('')
		else:
			if h == 0:
				print('UD')
			else:
				print('LR')
			continue
	for i in range(h):
		ans += 'R'
	for i in range(v):
		ans += 'U'
	for i in range(h):
		ans += 'L'
	for i in range(v):
		ans += 'D'
	print(ans)


from collections import Counter
t = int(input())
for _ in range(t):
	c = Counter(input())
	ud = min(c['U'], c['D'])
	lr = min(c['L'], c['R'])
	if ud == 0 and lr == 0:
		print(0)
	elif ud == 0:
		print(2)
		print('RL')
	elif lr == 0:
		print(2)
		print('UD')
	else:
		print(2 * (ud + lr))
		print(ud * 'U' + lr * 'R' + ud * 'D' + lr * 'L')


q = int(input())
while q:
	q += -1
	s = input()
	l = 0
	r = 0
	u = 0
	d = 0
	for i in s:
		if i == 'R':
			r += 1
		elif i == 'L':
			l += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	m1 = min(l, r)
	m2 = min(u, d)
	if m1 == 0:
		if m2 == 0:
			print(0)
		else:
			print(2)
			print('UD')
	elif m2 == 0:
		print(2)
		print('RL')
	else:
		print(2 * (m1 + m2))
		print('R' * m1, end='')
		print('U' * m2, end='')
		print('L' * m1, end='')
		print('D' * m2)


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


def examA():
	Q = I()
	ans = []
	for _ in range(Q):
		a = LI()
		a.sort()
		if a[0] == a[1]:
			if a[1] == a[2]:
				ans.append(0)
				continue
			else:
				a[0] += 1
				a[1] += 1
				if a[1] != a[2]:
					a[2] -= 1
		else:
			a[0] += 1
			if a[1] != a[2]:
				a[2] -= 1
			elif a[0] != a[1]:
				a[1] -= 1
				a[2] -= 1
		cur = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2])
		ans.append(cur)
	for v in ans:
		print(v)

def examB():
	Q = I()
	ans = []
	ansC = []
	for _ in range(Q):
		d = defaultdict(int)
		S = SI()
		for s in S:
			d[s] += 1
		height = min(d['U'], d['D'])
		width = min(d['R'], d['L'])
		cur = ''
		if height > 0 and width > 0:
			ans.append((height + width) * 2)
			for i in range(height):
				cur += 'U'
			for i in range(width):
				cur += 'R'
			for i in range(height):
				cur += 'D'
			for i in range(width):
				cur += 'L'
		elif height > 0 or width > 0:
			ans.append(2)
			if height == 0:
				cur = 'LR'
			else:
				cur = 'UD'
		else:
			ans.append(0)
		ansC.append(cur)
	for i in range(Q):
		print(ans[i])
		print(ansC[i])
	return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

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

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

def LSI():
	return list(map(str, sys.stdin.readline().split()))

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

def SI():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
inf = float('inf')
examB()


import sys
from collections import Counter

def solve():
	s = sys.stdin.readline()
	c = Counter(s)
	lr = min(c.get('L', 0), c.get('R', 0))
	ud = min(c.get('U', 0), c.get('D', 0))
	if lr == 0 or ud == 0:
		lr = min(lr, 1)
		ud = min(ud, 1)
	c['L'] = c['R'] = lr
	c['U'] = c['D'] = ud
	print(lr + lr + ud + ud)
	for ch in 'RULD':
		print(ch * c.get(ch, 0), end='')
	print()

def main():
	q = int(sys.stdin.readline())
	for _ in range(q):
		solve()
main()


q = int(input())
for case in range(q):
	instructions = [x for x in list(input())]
	U = instructions.count('U')
	D = instructions.count('D')
	L = instructions.count('L')
	R = instructions.count('R')
	if U > D:
		U = D
	if D > U:
		D = U
	if L > R:
		L = R
	if R > L:
		R = L
	if R == 0 and D == 0:
		print(0)
	elif R == 0:
		print(2)
		print('UD')
	elif D == 0:
		print(2)
		print('LR')
	else:
		print(U + D + L + R)
		print('U' * U + 'R' * R + 'D' * D + 'L' * L)


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)


import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	s = input()[:-1]
	cntU = s.count('U')
	cntD = s.count('D')
	cntL = s.count('L')
	cntR = s.count('R')
	minLR = min(cntR, cntL)
	minUD = min(cntU, cntD)
	if minLR > 0 and minUD > 0:
		ans = minLR * 2 + minUD * 2
		string = 'R' * minLR + 'U' * minUD + 'L' * minLR + 'D' * minUD
	elif minLR == 0:
		ans = min(minUD, 1) * 2
		string = 'U' * min(minUD, 1) + 'D' * min(minUD, 1)
	elif minUD == 0:
		ans = min(minLR, 1) * 2
		string = 'R' * min(minLR, 1) + 'L' * min(minLR, 1)
	else:
		ans = 0
		string = ''
	print(ans)
	print(string)


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()


t = int(input())
for _ in range(t):
	s = input()
	counts = {'D': 0, 'U': 0, 'L': 0, 'R': 0}
	for ss in s:
		counts[ss] += 1
	du = min(counts['D'], counts['U'])
	rl = min(counts['R'], counts['L'])
	if du == 0:
		rl = min(1, rl)
	if rl == 0:
		du = min(1, du)
	print(2 * (du + rl))
	print('D' * du + 'R' * rl + 'U' * du + 'L' * rl)


n = int(input())
for i in range(n):
	ch = input()
	x = min(ch.count('U'), ch.count('D'))
	y = min(ch.count('R'), ch.count('L'))
	ch2 = x * 'U' + y * 'R' + x * 'D' + y * 'L'
	if x == 0 and y != 0:
		print(2)
		print('LR')
	elif y == 0 and x != 0:
		print(2)
		print('UD')
	else:
		print(len(ch2))
		print(ch2)


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)


from collections import defaultdict
from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	Q = int(input())
	for _ in [0] * Q:
		order = defaultdict(int)
		for s in input():
			order[s] += 1
		l = r = min(order['L'], order['R'])
		u = d = min(order['U'], order['D'])
		if not l and u:
			u = d = 1
		if not u and l:
			l = r = 1
		ans = 'R' * r + 'U' * u + 'L' * l + 'D' * d
		print(len(ans))
		print(ans)
main()


import sys
q = int(input())
for i in range(q):
	s = input()
	s = sorted(s)
	lol = min(s.count('U'), s.count('D'))
	kek = min(s.count('L'), s.count('R'))
	ans = 'R' * kek + 'U' * lol + 'L' * kek + 'D' * lol
	if lol == 0 and kek == 0:
		print(0)
	elif lol == 0:
		print(2)
		print('LR')
	elif kek == 0:
		print(2)
		print('UD')
	else:
		print(len(ans))
		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)


q = int(input())
for _ in range(q):
	s = input()
	(L, R, D, U) = (s.count('L'), s.count('R'), s.count('D'), s.count('U'))
	l_ = abs(L - R)
	d_ = abs(D - U)
	ans = L + D + R + U - (l_ + d_)
	if ans == 0:
		print(0)
		print()
		continue
	if min(L, R) == 0 or (l_ == 0 and L == 0):
		print(2)
		print('DU')
		continue
	if min(D, U) == 0 or (d_ == 0 and D == 0):
		print(2)
		print('LR')
		continue
	print(ans)
	print('L' * (max(L, R) - l_) + 'D' * (max(D, U) - d_) + 'R' * (max(L, R) - l_) + 'U' * (max(D, U) - d_))


q = int(input())
for i in range(q):
	s = input()
	(u, d, l, r) = (s.count('U'), s.count('D'), s.count('L'), s.count('R'))
	(z, x) = (min(u, d), min(l, r))
	if z != 0 and x != 0:
		print(2 * (z + x))
		print('U' * z + 'R' * x + 'D' * z + 'L' * x)
	elif z == 0:
		if x == 0:
			print(0)
			print()
		else:
			print(2)
			print('RL')
	elif x == 0:
		print(2)
		print('UD')


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()


t = int(input())
for c in range(t):
	cad = input()
	(U, L, R, D) = (0, 0, 0, 0)
	for i in cad:
		if i == 'L':
			L += 1
		elif i == 'R':
			R += 1
		elif i == 'U':
			U += 1
		else:
			D += 1
	a = min(U, D)
	b = min(L, R)
	if a and b:
		print(2 * a + 2 * b)
		for i in range(a):
			print('U', end='')
		for i in range(b):
			print('L', end='')
		for i in range(a):
			print('D', end='')
		for i in range(b):
			print('R', end='')
		print()
	elif a:
		print(2)
		print('UD')
	elif b:
		print(2)
		print('LR')
	else:
		print(0)
		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())):
	s = input()
	(a, b, c, d) = (s.count('U'), s.count('D'), s.count('L'), s.count('R'))
	ns = ''
	if min(a, b) != 0 and min(c, d) != 0:
		for _ in range(min(a, b)):
			ns += 'U'
		for _ in range(min(c, d)):
			ns += 'R'
		for _ in range(min(a, b)):
			ns += 'D'
		for _ in range(min(c, d)):
			ns += 'L'
	elif min(a, b) == 0 and min(c, d) != 0:
		ns = 'LR'
	elif min(c, d) == 0 and min(a, b) != 0:
		ns = 'UD'
	else:
		ns = ''
	print(len(ns))
	print(ns)


for _ in range(int(input())):
	s = input()
	orgv = 1
	visited = set()
	visited.add('0,0')
	poss = True
	(x1, x2, y1, y2) = (0, 0, 0, 0)
	for i in s:
		if i == 'L':
			x1 += 1
		if i == 'R':
			x2 += 1
		if i == 'U':
			y1 += 1
		if i == 'D':
			y2 += 1
	xmoves = min(x1, x2)
	ymoves = min(y1, y2)
	if xmoves == ymoves == 0:
		print(0)
	else:
		(x, y) = (0, 0)
		x1 = x2 = xmoves
		y1 = y2 = ymoves
		ans = ['-'] * ((xmoves + ymoves) * 2)
		for i in range(xmoves + ymoves + xmoves + ymoves):
			poss = [str(x - 1) + ',' + str(y), str(x + 1) + ',' + str(y), str(x) + ',' + str(y + 1), str(x) + ',' + str(y - 1)]
			if y1 > 0 and poss[2] not in visited:
				visited.add(poss[2])
				ans[i] = 'U'
				y1 -= 1
				y += 1
			elif x1 > 0 and poss[0] not in visited:
				visited.add(poss[0])
				ans[i] = 'L'
				x1 -= 1
				x -= 1
			elif x2 > 0 and poss[1] not in visited:
				visited.add(poss[1])
				ans[i] = 'R'
				x2 -= 1
				x += 1
			elif y2 > 0 and poss[3] not in visited:
				visited.add(poss[3])
				ans[i] = 'D'
				y2 -= 1
				y -= 1
			else:
				if x1 + y1 + y2 + x2 <= 1:
					break
				poss = False
				if xmoves > 0:
					print('2\nLR')
				if ymoves > 0:
					print('2\nUD')
				break
		if poss:
			last = '' + 'L' * x1 + 'R' * x2 + 'U' * y1 + 'D' * y2
			ans = ''.join(ans).replace('-', '') + last
			print(len(ans))
			print(ans)


a = int(input())
for i in range(a):
	cache = {}
	b = input()
	(r, l, u, d) = (b.count('R'), b.count('L'), b.count('U'), b.count('D'))
	pan = min(r, l)
	pan_up = min(u, d)
	c = 'R' * pan + 'D' * pan_up + 'L' * pan + 'U' * pan_up
	if len(set(c)) < 4:
		print(len(set(c)))
		print(''.join(set(c)))
	else:
		print(len(c))
		print(c)


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)


from collections import defaultdict
for _ in range(int(input())):
	(l, r, u, d) = (0, 0, 0, 0)
	for char in input():
		if char == 'L':
			l += 1
		elif char == 'R':
			r += 1
		elif char == 'U':
			u += 1
		else:
			d += 1
	l = min(l, r)
	d = min(u, d)
	if d == 0:
		l = min(l, 1)
	elif l == 0:
		d = min(d, 1)
	print(2 * (l + d))
	out = 'R' * l + 'U' * d + 'L' * l + 'D' * d
	print(out)


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)


from collections import *
import sys

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
t = ri()
for _ in range(t):
	s = input()
	d = defaultdict(int)
	d['R'] = 0
	d['L'] = 0
	d['U'] = 0
	d['D'] = 0
	for letter in s:
		d[letter] += 1
	lower_y = min(d['U'], d['D'])
	lower_x = min(d['R'], d['L'])
	if lower_x > 0 and lower_y > 0:
		print(lower_x * 2 + lower_y * 2)
		print('U' * lower_y + 'R' * lower_x + 'D' * lower_y + 'L' * lower_x)
	elif lower_x > 0:
		print(2)
		print('RL')
	elif lower_y > 0:
		print(2)
		print('UD')
	else:
		print(0)
		print('')


from collections import Counter
for _ in range(int(input())):
	s = list(input())
	c = Counter(s)
	if c['L'] > 0 and c['R'] > 0:
		if c['U'] == 0 or c['D'] == 0:
			print(2)
			print('LR')
			continue
	if c['U'] > 0 and c['D'] > 0:
		if c['L'] == 0 or c['R'] == 0:
			print(2)
			print('UD')
			continue
	summ = 2 * min(c['L'], c['R']) + 2 * min(c['U'], c['D'])
	print(summ)
	w = ''
	for i in range(min(c['L'], c['R'])):
		w += 'R'
	for i in range(min(c['U'], c['D'])):
		w += 'U'
	for i in range(min(c['L'], c['R'])):
		w += 'L'
	for i in range(min(c['U'], c['D'])):
		w += 'D'
	print(w)


import sys
import bisect as bi
import math
from collections import defaultdict as dd
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	s = sin().strip()
	l = r = u = d = 0
	for i in s:
		if i == 'L':
			l += 1
		elif i == 'D':
			d += 1
		elif i == 'U':
			u += 1
		else:
			r += 1
	a = [l, r, u, d]
	a.sort()
	if (l > 0 and r > 0) and (u == 0 or d == 0):
		print(2)
		print('LR')
	elif (u > 0 and d > 0) and (l == 0 or r == 0):
		print(2)
		print('UD')
	elif a[0:3] == [0, 0, 0]:
		print(0)
		print()
	else:
		hor = min(l, r)
		ver = min(u, d)
		print(2 * hor + 2 * ver)
		s1 = 'L' * hor + 'D' * ver + 'R' * hor + 'U' * ver
		print(s1)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

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

def fmi():
	return map(float, stdin.readline().split())

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

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()

def sieve(x):
	a = [True] * (x + 1)
	sq = floor(sqrt(x))
	for i in range(3, sq + 1, 2):
		if a[i]:
			for j in range(i * i, x + 1, i):
				a[j] = False
	if x > 1:
		p = [2]
	else:
		p = []
	for i in range(3, x + 1, 2):
		if a[i]:
			p.append(i)
	return p
for _ in range(ii()):
	a = lsi()
	d = u = r = l = 0
	for i in a:
		if i == 'D':
			d += 1
		elif i == 'U':
			u += 1
		elif i == 'L':
			l += 1
		else:
			r += 1
	if l > r:
		l = r
	else:
		r = l
	if d > u:
		d = u
	else:
		u = d
	if l and (not u):
		l = r = 1
	elif u and (not l):
		u = d = 1
	print(u + d + l + r)
	print('R' * r + 'D' * d + 'L' * l + 'U' * u)


def calculate_path(path):
	global directions
	x = y = 0
	for d in path:
		x += directions[d][0]
		y += directions[d][1]
	return (x, y)
directions = {'L': (-1, 0), 'R': (1, 0), 'U': (0, 1), 'D': (0, -1)}
t = int(input())
for _ in range(t):
	log = dict()
	path = input()
	(endx, endy) = calculate_path(path)
	for direction in path:
		if endx > 0 and direction == 'R':
			endx -= 1
		elif endx < 0 and direction == 'L':
			endx += 1
		elif endy > 0 and direction == 'U':
			endy -= 1
		elif endy < 0 and direction == 'D':
			endy += 1
		else:
			if direction not in log:
				log[direction] = 0
			log[direction] += 1
	new_path = 'L' * log.get('L', 0) + 'U' * log.get('U', 0) + 'R' * log.get('R', 0) + 'D' * log.get('D', 0)
	if set(new_path) in ({'L', 'R'}, {'U', 'D'}):
		new_path = ''.join(set(new_path))
	print(len(new_path), new_path, sep='\n')


for _ in range(int(input())):
	arr = list(map(str, list(input())))
	r = arr.count('R')
	l = arr.count('L')
	u = arr.count('U')
	d = arr.count('D')
	count = len(arr)
	path = ''
	if u - d != 0:
		count -= abs(u - d)
		u = d = min(u, d)
	if r - l != 0:
		count -= abs(r - l)
		r = l = min(r, l)
	if r == 0 and u == 0:
		print(0)
		continue
	elif r == 0:
		print('2\nUD')
		continue
	elif u == 0:
		print('2\nRL')
		continue
	path += 'U' * u + 'R' * r + 'D' * d + 'L' * l
	print(count)
	print(path)


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)


ordering = {'U': 0, 'L': 1, 'D': 2, 'R': 3}
from collections import Counter as C
q = int(input())
for _ in range(q):
	s = input()
	n = len(s)
	cnts = C(s)
	if cnts['U'] == 0 or cnts['D'] == 0:
		cnts['L'] = min(1, cnts['L'])
		cnts['R'] = min(1, cnts['R'])
	if cnts['L'] == 0 or cnts['R'] == 0:
		cnts['U'] = min(1, cnts['U'])
		cnts['D'] = min(1, cnts['D'])
	cnts['U'] = min(cnts['U'], cnts['D'])
	cnts['D'] = cnts['U']
	cnts['L'] = min(cnts['L'], cnts['R'])
	cnts['R'] = cnts['L']
	ansArr = ['U'] * cnts['U'] + ['D'] * cnts['D'] + ['L'] * cnts['L'] + ['R'] * cnts['R']
	ansArr.sort(key=lambda x: ordering[x])
	print(len(ansArr))
	print(''.join(ansArr))


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)


from copy import copy

def arr_float_inp():
	return [float(s) for s in input().split()]

def arr_int_inp():
	return [int(s) for s in input().split()]

def int_inp():
	return int(input())

def float_inp():
	return float(input())
for _ in range(int_inp()):
	arr = {'U': 0, 'R': 0, 'D': 0, 'L': 0}
	for ch in input():
		arr[ch] += 1
	if min(arr['U'], arr['D']) == 0 and min(arr['L'], arr['R']) != 0:
		print(2)
		print('LR')
	elif min(arr['U'], arr['D']) != 0 and min(arr['L'], arr['R']) == 0:
		print(2)
		print('UD')
	else:
		out = 'L' * min(arr['L'], arr['R'])
		out += 'D' * min(arr['U'], arr['D'])
		out += 'R' * min(arr['L'], arr['R'])
		out += 'U' * min(arr['U'], arr['D'])
		print(len(out))
		print(out)


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


for _ in range(int(input())):
	seq = list(input())
	counts = [0, 0, 0, 0]
	for c in seq:
		if c == 'U':
			counts[0] += 1
		elif c == 'D':
			counts[1] += 1
		elif c == 'L':
			counts[2] += 1
		elif c == 'R':
			counts[3] += 1
	mi_vert = mi_hor = 0
	mi_vert = min(counts[0], counts[1])
	mi_hor = min(counts[2], counts[3])
	if mi_vert == 0 and counts[2] > 0 and (counts[3] > 0):
		mi_hor = 1
	if mi_hor == 0 and counts[0] > 0 and (counts[1] > 0):
		mi_vert = 1
	ans_arr = ['U'] * mi_vert + ['L'] * mi_hor + ['D'] * mi_vert + ['R'] * mi_hor
	ans = ''.join(ans_arr)
	print(len(ans_arr))
	print(ans)


T = int(input(' '))
for vv in range(T):
	a = input()
	n = len(a)
	l = 0
	r = 0
	u = 0
	d = 0
	for i in range(n):
		if a[i] == 'L':
			l += 1
		elif a[i] == 'R':
			r += 1
		elif a[i] == 'U':
			u += 1
		elif a[i] == 'D':
			d += 1
	h = min(l, r)
	v = min(u, d)
	s = ''
	an = 0
	if h != 0 and v != 0:
		for i in range(v):
			s = s + 'U'
		for i in range(h):
			s = s + 'L'
		for i in range(v):
			s = s + 'D'
		for i in range(h):
			s = s + 'R'
		an = 2 * h + 2 * v
	elif h == 0 and v != 0:
		an = 2
		s = 'UD'
	elif h != 0 and v == 0:
		an = 2
		s = 'LR'
	print(an)
	print(s)


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')


n = int(input())
for i in range(n):
	dicts = {}
	kk = str(input())
	for j in kk:
		if j not in dicts:
			dicts[j] = 1
		else:
			dicts[j] += 1
	if len(dicts) == 1:
		print(0)
		print('')
		continue
	if len(dicts) < 4:
		if 'L' in dicts and 'R' in dicts:
			print('2')
			print('LR')
		elif 'U' in dicts and 'D' in dicts:
			print('2')
			print('UD')
		else:
			print('0')
			print('')
		continue
	if len(dicts) == 4:
		mins1 = min(dicts['U'], dicts['D'])
		mins = min(dicts['L'], dicts['R'])
		strs = 'U' * mins1
		strs += 'R' * mins
		strs += 'D' * mins1
		strs += 'L' * mins
		v = len(strs)
		print(v)
		print(strs)


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 sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

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

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	s = inputstring()
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	L = ['L'] * min(l, r)
	R = ['R'] * min(l, r)
	U = ['U'] * min(u, d)
	D = ['D'] * min(u, d)
	if min(l, r) == 0 and min(u, d) == 0:
		print(0)
	elif min(l, r) == 0:
		print(2)
		print('DU')
	elif min(u, d) == 0:
		print(2)
		print('LR')
	else:
		ans = U + R + D + L
		print(len(ans))
		for c in ans:
			print(c, end='')
		print()


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)