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

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.*;
import java.lang.Math;
 
public class Main4{
    public static void main(String[] args) throws IOException{
        BufferedReader teclado = new BufferedReader(new InputStreamReader(System.in));
        int operaciones = Integer.parseInt(teclado.readLine());
        for(int k = 0; k < operaciones; k++){    
            String pre = teclado.readLine();
            StringBuilder comandos = new StringBuilder(pre);
            int  R = 0, L = 0, U = 0, D = 0;
            if(Pattern.compile("\\d").matcher(comandos).find()){
                int j = 0;
                int[] r = new int[comandos.length()];
                int[] l = new int[comandos.length()];
                int[] u = new int[comandos.length()];
                int[] d = new int[comandos.length()];
                for(int i = 0; i < comandos.length(); i++){
                    if(comandos.charAt(i) == 'R'){
                        R += Character.getNumericValue(comandos.charAt(i+1));
                        while(r[j] != 0){
                            j++;
                        }
                        r[j] = Character.getNumericValue(comandos.charAt(i+1));
                        j = 0;
                    }
                    else if(comandos.charAt(i) == 'L'){
                        L += Character.getNumericValue(comandos.charAt(i+1));
                        while(l[j] != 0){
                            j++;
                        }
                        l[j] = Character.getNumericValue(comandos.charAt(i+1));
                        j = 0;
                    }
                    else if(comandos.charAt(i) == 'U'){
                        U += Character.getNumericValue(comandos.charAt(i+1));
                        while(u[j] != 0){
                            j++;
                        }
                        u[j] = Character.getNumericValue(comandos.charAt(i+1));
                        j = 0;
                    }
                    else if(comandos.charAt(i) == 'D'){
                        D += Character.getNumericValue(comandos.charAt(i+1));
                        while(d[j] != 0){
                            j++;
                        }
                        d[j] = Character.getNumericValue(comandos.charAt(i+1));
                        j = 0;
                    }
                }
                if(R == 0 && L == 0 && U == 0 && D == 0){
                    System.out.println(0);
                    System.out.println("");
                }
                else{
                    Handler robo = new Handler(r, l, u, d, R, L, U, D);
                    robo.comparar1();
                    robo.comparar2();
                    int[] nuevoR = robo.getRight(), nuevoL = robo.getLeft(), nuevoU = robo.getUp(), nuevoD = robo.getDown();

                    if(nuevoR[0] == 0 && nuevoL[0] == 0){
                        for(int i = 0; i < nuevoU.length; i++){
                            if(nuevoU[i] == 1){
                                for(int m = 0; m < nuevoD.length; m++){
                                    if(nuevoD[m] == 1){
                                        System.out.println(2);
                                        System.out.println("U1D1");
                                        break;
                                    }
                                    if(nuevoD[m+1] == 0){
                                        System.out.println("");
                                        break;
                                    }
                                }
                            } 
                        }
                    }
                    else if(nuevoD[0] == 0 && nuevoU[0] == 0){
                        for(int i = 0; i < nuevoR.length; i++){
                            if(nuevoR[i] == 1){
                                for(int m = 0; m < nuevoL.length; m++){
                                    if(nuevoL[m] == 1){
                                        System.out.println(2);
                                        System.out.println("L1R1");
                                        break;
                                    }
                                    if(nuevoL[m+1] == 0){
                                        System.out.println("");
                                        break;
                                    }
                                }
                            } 
                        }
                    }
                    else{
                        String retornar = "";
                        for(int t: nuevoR){
                            if(t == 0){
                                break;
                            }
                            retornar = retornar + "R" + Integer.toString(t);
                        }
                        for(int t: nuevoU){
                            if(t == 0){
                                break;
                            }
                            retornar = retornar + "U" + Integer.toString(t);
                        }
                        for(int t: nuevoL){
                            if(t == 0){
                                break;
                            }
                            retornar = retornar + "L" + Integer.toString(t);
                        }
                        for(int t: nuevoD){
                            if(t == 0){
                                break;
                            }
                            retornar = retornar + "D" + Integer.toString(t);
                        }
                        System.out.println(retornar.length()/2);
                        System.out.println(retornar);
                    }
                }
            }
            else{
                for(int i = 0; i < comandos.length(); i++){
                    if(comandos.charAt(i) == 'R'){
                        R++;
                    }
                    else if(comandos.charAt(i) == 'L'){
                        L++;
                    }
                    else if(comandos.charAt(i) == 'U'){
                        U++;
                    }
                    else{
                        D++;
                    }
                }
                if(R == 0 && L == 0 && D == 0 && U == 0){
                    System.out.println(0);
                    System.out.println("");
                }
                else{
                    if(R > L){
                        for(int j = 0; j < Math.abs(R - L); j++){
                            comandos.deleteCharAt(comandos.lastIndexOf("R"));
                        }
                        R = L;
                    }
                    else if(L > R){
                        for(int j = 0; j < Math.abs(R - L); j++){
                            comandos.deleteCharAt(comandos.lastIndexOf("L"));
                        }
                        L = R;
                    }
                    if(U > D){
                        for(int j = 0; j < Math.abs(U - D); j++){
                            comandos.deleteCharAt(comandos.lastIndexOf("U"));
                        }
                        U = D;
                    }
                    else if(D > U){
                        for(int j = 0; j < Math.abs(U - D); j++){
                            comandos.deleteCharAt(comandos.lastIndexOf("D"));
                        }
                        D = U;
                    }
                    if(comandos.length() == 0){
                        System.out.println(0);
                        System.out.println("");
                    }
                    else{
                        Handler robo = new Handler(comandos, R, U);
                        String respuesta = robo.reordenar();
                        System.out.println(respuesta.length());
                        System.out.println(respuesta);
                    }
                }
            }
        }
    }
}
 
interface Robot{
    public String reordenar();
    public void comparar1();
    public void comparar2();
}
 
class Handler implements Robot{
    private StringBuilder str;
    private int R, L, U, D;
    private int[] right, left, up, down;
 
    Handler(StringBuilder palabra, int de, int ar){
        this.str = palabra;
        this.R = de;
        this.L = de;
        this.U = ar;
        this.D = ar;
    }

    Handler(int[] r, int[] l, int[] u, int[] d, int R, int L, int U, int D){
        this.right = r;
        this.left = l;
        this.up = u;
        this.down = d;
        this.R = R;
        this.L = L;
        this.U = U;
        this.D = D;
    }

    public int[] getRight() {
        return right;
    }

    public int[] getLeft() {
        return left;
    }

    public int[] getUp() {
        return up;
    }

    public int[] getDown() {
        return down;
    }
 
    @Override
    public String reordenar(){
        String A, B, C, S;
        if(U == 0 && D == 0){
            return "RL";
        }
        else if(R == 0 && L == 0){
            return "UD";
        }
        
        A = str.substring(0, U).replaceAll("L|R|D|U", "U");
        B = str.substring(U, U+R).replaceAll("L|R|D|U", "R");
        C = str.substring(U+R, U+R+D).replaceAll("L|R|D|U", "D");
        S = str.substring(U+R+D, U+R+D+L).replaceAll("L|R|D|U", "L");
        
        return A+B+C+S;
    }

    @Override
    public void comparar1(){
        while(R != L){
            if(R > L){
                for(int i = 0; i < right.length; i++) {
                    if(R-right[i] == L){
                        R -= right[i];
                        right[i] = 0;
                        return;
                    }
                    else if(right[i+1] == 0){
                        R -= right[i];
                        right[i] = 0;
                        break;
                    }
                }
            }
            if(L > R){
                for(int i = 0; i < left.length; i++) {
                    if(L-left[i] == R){
                        L -= left[i];
                        left[i] = 0;
                        return;
                    }
                    else if(left[i+1] == 0 || i == left.length-1){
                        L -= left[i];
                        left[i] = 0;
                        break;
                    }
                }
            }
            if(right[0] == 0){
                fillzeros(left);
                return;
            }
            else if(left[0] == 0){
                fillzeros(right);
                return;
            }
        }
    }

    @Override
    public void comparar2(){
        while(U != D){
            if(U > D){
                for(int i = 0; i < up.length; i++) {
                    if(U-up[i] == D){
                        U -= up[i];
                        up[i] = 0;
                        return;
                    }
                    else if(up[i+1] == 0 || i == up.length-1){
                        U -= up[i];
                        up[i] = 0;
                        break;
                    }
                }
            }
            if(D > U){
                for(int i = 0; i < down.length; i++) {
                    if(D-down[i] == U){
                        D -= down[i];
                        down[i] = 0;
                        return;
                    }
                    else if(down[i+1] == 0 || i == down.length-1){
                        D -= down[i];
                        down[i] = 0;
                        break;
                    }
                }
            }
            if(up[0] == 0){
                fillzeros(down);
                return;
            }
            else if(down[0] == 0){
                fillzeros(up);
                return;
            }
        }
    }

    public void fillzeros(int[] matriz){
        for(int i = 0; i < matriz.length; i++){
            if(matriz[i] == 0){
                break;
            }
            matriz[i] = 0;
        }
    }
}