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.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collections;
public class Main{
    public static void main(String[] args) throws IOException{
        ArrayList<Object> output = new ArrayList<Object>();
        BufferedReader keyb = new BufferedReader(new InputStreamReader(System.in));
        Integer q = Integer.parseInt(keyb.readLine());
        while(q > 0){
            String instruction = keyb.readLine();
            String typerobot;
            if(instruction.contains("1") || instruction.contains("2")){
                typerobot = "Beta";
            }
            else{
                typerobot = "Alpha";
            }
            String solution = Handler.solveIt(instruction, typerobot);
            if(typerobot == "Alpha"){
                output.add(solution.length());
            }
            else{
                output.add(solution.length() / 2);
            }
            output.add(solution);
            q = q - 1;
        }
        for (Object object : output) {
            System.out.println(object);
            
        } 
    }
}
class Position{
    public Position(int x, int y){
        this.x = x;
        this.y = y;
    }
    public void increaseX(int increaseValue){
        this.x = this.x + increaseValue;
    }
    public void increaseY(int increaseValue){
        this.y = this.y + increaseValue;
    }

    public int getX(){
        return this.x;
    }
    public int getY(){
        return this.y;
    }

    private int x;
    private int y;
}

class Handler{
    public interface Robot{ //interfae para ambos tipos de robot
        public Position searchProblem(String instruction);
        public boolean endsCorrectly();
        public boolean visited(Position pos);
        public HashMap<String, Integer> getInfo(String instruction);
        public String output(HashMap<String, Integer> informacion, String instruction);
        public String concatenator(HashMap<String,Integer> info);
    }
    static class BetaRobot implements Robot{
        public BetaRobot(){
            this.pos = new Position(0, 0); //todos parten en el inicio 0,0
            states = new ArrayList<Position>(); //acá almacenaré las posiciones por las que ha pasado el robot

        }
        public String concatenator(HashMap<String,Integer> informacion){
            String new_instruction = "";
            if(info.get("U")%2 == 0){
                new_instruction += String.join("", Collections.nCopies(informacion.get("U")/2, "U2"));

            }
            else{
                new_instruction += String.join("", Collections.nCopies((informacion.get("U") - 1)/2, "U2"));
                new_instruction += "U1";
            }
            if(info.get("R")%2 == 0){
                new_instruction += String.join("", Collections.nCopies(informacion.get("R")/2, "R2"));

            }
            else{
                new_instruction += String.join("", Collections.nCopies((informacion.get("R") - 1)/2, "R2"));
                new_instruction += "R1";
            }
            if(info.get("D")%2 == 0){
                new_instruction += String.join("", Collections.nCopies(informacion.get("D")/2, "D2"));

            }
            else{
                new_instruction += String.join("", Collections.nCopies((informacion.get("D") - 1)/2, "D2"));
                new_instruction += "D1";
            }
            if(info.get("L")%2 == 0){
                new_instruction += String.join("", Collections.nCopies(informacion.get("L")/2, "L2"));

            }
            else{
                new_instruction += String.join("", Collections.nCopies((informacion.get("L") - 1)/2, "L2"));
                new_instruction += "L1";
            }
            return new_instruction;
        }
        public String output(HashMap<String, Integer> informacion, String instruction){ //ESTÁ RECIBIENDO UNA INSTRUCIÓN INCORRECTA
            if(informacion.get("U") == 0 && informacion.get("D") == 0){
                return "L1R1";
            }
            else if(informacion.get("L") == 0 && informacion.get("R") == 0){
                return "U1D1";
            }
            else{
                /*
                int i = 0;
                String new_instruction = "";
                while(i < instruction.length()){
                    String times = String.valueOf(instruction.charAt(i + 1));
                    //System.out.println("The value of times is: " + times);
                    String order = String.valueOf(instruction.charAt(i));
                    new_instruction += order;
                    new_instruction += times;
                    i = i + 2;
                }*/
                return concatenator(info);
            }
        }
        public Position searchProblem(String instruction){
            int i = 0;
            while(i < instruction.length()){
                int times;
                times = Integer.parseInt(String.valueOf(instruction.charAt(i + 1)));
                String order = String.valueOf(instruction.charAt(i));
                if(order == "U"){
                    pos.increaseY(times);
                }
                if(order == "D"){
                    pos.increaseY(-times); //esto es -times
                }
                if(order == "R"){
                    pos.increaseX(times);
                }
                if(order == "L"){
                    pos.increaseX(-times);
                }
                i = i + 2;
            } 
    
            if(!this.visited(pos)){ //si es que no la he visitado
                states.add(new Position(pos.getX(), pos.getY())); //la agrego
            }
            else{
                return pos; //de lo contrario, encontré la posición en la cual hay problema
                }
            //si llego a este punto => no problemas en la ruta
            //como ya revisé si llegué al i
            return null; //esto significa que salió todo bien
        }
        public boolean endsCorrectly(){ //indica si tiene o no la cantidad correcta de ordenes para terminar en 0,0
            if(info.get("U") == info.get("D")){
                if(info.get("R") == info.get("L")){
                    return true;
                }
            }
            return false;
        }
        public boolean visited(Position pos){ //indica si ya pasó o no por una posición
            for(Position position : states) {
                if((position.getX() == pos.getX()) && (position.getY() == pos.getY())){
                    return true;
                }  
            }
            return false;
        }
        public HashMap<String, Integer> getInfo(String instruction){
            info = new HashMap<>();
            info.put("U", 0);
            info.put("D", 0);
            info.put("R", 0);
            info.put("L", 0);
            int i = 0;
            while(i < instruction.length()){
                int times;
                times = Integer.parseInt(String.valueOf(instruction.charAt(i + 1)));
                String order = String.valueOf(instruction.charAt(i));
                int currentValue = info.get(order);
                info.replace(order, currentValue, currentValue + times);
                i = i + 2;
            } 
            return info;
        }
        

        private HashMap<String, Integer> info;
        private Position pos;
        private ArrayList<Position> states;
    }
            
        
    
    static class AlphaRobot implements Robot{ //this class will model the simple robot
        public AlphaRobot(){
            this.pos = new Position(0, 0); //todos parten en el inicio 0,0
            states = new ArrayList<Position>(); //acá almacenaré las posiciones por las que ha pasado el robot
            //states.add(pos); no la agregaré para que así poder usar la condición de updatePos
        }
        public String concatenator(HashMap<String,Integer> info){
            String new_instruction = "";
            new_instruction += String.join("", Collections.nCopies(info.get("U"), "U"));
            new_instruction += String.join("", Collections.nCopies(info.get("R"), "R"));
            new_instruction += String.join("", Collections.nCopies(info.get("D"), "D"));
            new_instruction += String.join("", Collections.nCopies(info.get("L"), "L"));
            return new_instruction;
        }
        public String output(HashMap<String, Integer> informacion, String instruction){
            if(informacion.get("U") == 0 && informacion.get("D") == 0){
                return "LR";
            }
            else if(informacion.get("L") == 0 && informacion.get("R") == 0){
                return "UD";
            }
            else{
                return this.concatenator(informacion);
            }
        }

        public Position searchProblem(String instruction){
            for(int i = 0; i < instruction.length(); i++){ //recorreré el string de instrucciones
                char order = instruction.charAt(i); //almacena una orden (char)
                if(order == 'U'){
                    pos.increaseY(1);
                }
                if(order == 'D'){
                    pos.increaseY(-1);
                }
                if(order == 'R'){
                    pos.increaseX(1);
                }
                if(order == 'L'){
                    pos.increaseX(-1);
                }
                //en este punto estáre en una nueva posición
                //if(pos.getX() == 0 && pos.getY() == 0){}
                if(!this.visited(pos)){ //si es que no la he visitado
                    states.add(new Position(pos.getX(), pos.getY())); //la agrego
                }
                else{
                    return pos; //de lo contrario, encontré la posición en la cual hay problema
                }
            }
            //si llego a este punto => no problemas en la ruta
            //como ya revisé si llegué al i
            return null; //esto significa que salió todo bien
        }
        public boolean visited(Position pos){ //indica si ya pasó o no por una posición
            for(Position position : states) {
                if((position.getX() == pos.getX()) && (position.getY() == pos.getY())){
                    return true;
                }  
            }
            return false;
        }
        public boolean endsCorrectly(){ //indica si tiene o no la cantidad correcta de ordenes para terminar en 0,0
            if(info.get("U") == info.get("D")){
                if(info.get("R") == info.get("L")){
                    return true;
                }
            }
            return false;
        }
    
        public HashMap<String, Integer> getInfo(String instruction){
            info.put("U", 0);
            info.put("D", 0);
            info.put("R", 0);
            info.put("L", 0);
            for(int i = 0; i < instruction.length(); i++){
                String order = String.valueOf(instruction.charAt(i));
                int currentValue = info.get(order);
                info.replace(order, currentValue, currentValue + 1);   
            }
            return info;
        }
        private HashMap<String, Integer> info = new HashMap<>();
        private Position pos;
        private ArrayList<Position> states;
    }
    public static String solveIt(String instruction, String typerobot){
        //usar typeRobot
        //implementar input y output function
        Robot robot;
        if(typerobot == "Alpha"){
            robot = new AlphaRobot();
        }
        else{
            robot  = new BetaRobot();
        }
        HashMap<String, Integer> info = robot.getInfo(instruction);
        /*System.out.println("R: " + info.get("R"));
        System.out.println("L: " + info.get("L"));
        System.out.println("U: " + info.get("U"));
        System.out.println("D: " + info.get("D"));*/
        if(robot.endsCorrectly()){
            Position problem = robot.searchProblem(instruction);
            if(problem == null){ //es decir, no hay problema
                return robot.output(info, instruction);
            }
            else{
                //en este caso consto de correcta cantidad de ordenes, pero hay al menos un error del tipo dos movimientos de x o dos de y consecutivos
                if(info.get("U") == 0 && info.get("D") == 0){
                    return robot.output(info,"LR");
                }
                else if(info.get("L") == 0 && info.get("R") == 0){
                    return robot.output(info, "UD");
                }
                else{
                    return robot.output(info, instruction);
                }
            }
        }
        else{
            //igualo la cantidad de U y D, y de L y R
            if(info.get("U") > info.get("D")){
                int dif = info.get("U") - info.get("D");
                int currentValue = info.get("U");
                info.replace("U", currentValue, currentValue - dif);
            }
            if(info.get("D") > info.get("U")){
                int dif = info.get("D") - info.get("U");
                int currentValue = info.get("D");
                info.replace("D", currentValue, currentValue - dif);
            }
            if(info.get("L") > info.get("R")){
                int dif = info.get("L") - info.get("R");
                int currentValue = info.get("L");
                info.replace("L", currentValue, currentValue - dif);
            }
            if(info.get("R") > info.get("L")){
                int dif = info.get("R") - info.get("L");
                int currentValue = info.get("R");
                info.replace("R", currentValue, currentValue - dif);
            }
            if(info.get("U") == 0 && info.get("D") == 0 && info.get("L") == 0 && info.get("R") == 0){
                return "";
            }
            if(info.get("U") == 0){
                return robot.output(info, "LR");
            }
            if(info.get("L") == 0){
                return robot.output(info, "UD");
            }
            return robot.output(info, instruction);
        }

      }
}