Problem: 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 ≤ q ≤ 2 ⋅ 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 (∑ |s| ≤ 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".

Solution (in PYTHON3):

Solution:
from fractions import gcd
# from datetime import date, timedelta
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
# input = sys.stdin.readline

# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
# 1 0 1 0 1 0 1 1 0 1  0  1  0  1  0  1  1  0  1  0  1  0  1  0  1  1  0   1 0  1  0  1  0  1  1  0 

def main():
    # t = int(input())
    # for _ in range(t):
    #     n = int(input())
    #     if n == 0:
    #         print(-1)
    #         continue
    #     l = []
    #     d = defaultdict(int)
    #     ans = 0
    #     oo,zz,oz,zo = 0,0,0,0
    #     for j in range(n):
    #         s = input()
    #         if d[s] == 1:
    #             s = s[::-1]
    #             ans+=1
    #         l.append(d)
    #         if s[0] == "0" and s[-1] == "0":
    #             zz+=1
    #         if s[0] == "0" and s[-1] == "1":
    #             zo+= 1
    #         if s[0] == "1" and s[-1] == "0":
    #             oz += 1
    #         if s[0] == "1" and s[-1] == "1":
    #             oo += 1

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

    # n = int(input())
    # a = list(map(int, input().split()))
    
    # l = []
    # ind = []
    # s = a[0]
    # c = 1
    # for i in range(1, n):
    #     if s < a[i]:
    #         c += 1
    #     else:
    #         l.append(c)
    #         ind.append(i - 1)
    #         c = 1
    #     s = a[i]
    # l.append(c)
    # ind.append(i)
    # #print(l, ind)
    # ans = max(l)
    # for i in range(len(ind)-1):
    #     j = ind[i]
    #     if a[j - 1] < a[j + 1]:
    #         ans = max(ans, l[i] + l[i + 1] - 1)
    # print(ans)


    


        
            



if __name__ == '__main__':
    main()