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 static java.lang.Integer.min;
 
public class Main {
        
    public static void main(String[] args) throws IOException{
        Handler.manejar();
    }
}

class Handler{
    static void manejar() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());
        Robot[] robots = new Robot[q];
        for(int i = 0; i<q ;i++)
        {
            String linea = br.readLine();
            if (linea.matches(".*\\d.*")) //Si encuentra al menos un numero, es el robot avanzado
            {
                Robot robot = new RobotAvanzado();
                for (int j = 0; j<linea.length();j+=2)
                {
                    int mov = Character.getNumericValue(linea.toCharArray()[j+1]);
                    char ch = linea.toCharArray()[j];
                    robot.mover(ch, mov);
                }
                robot.movimientos();
                robots[i] = robot;
            }
            else
            {
                Robot robot = new RobotBasico();
                for(char ch : linea.toCharArray())
                {
                    robot.mover(ch, i);
                }
                robot.movimientos();
                robots[i] = robot;
            }
        }
        for(Robot robot : robots) robot.Imprimir();
    }
}

interface Robot
{
    void Imprimir();
    void mover(char d, int c);
    void movimientos();
}

class RobotBasico implements Robot
{
    int R = 0;
    int L = 0;
    int U = 0;
    int D = 0;
    String camino;
    public RobotBasico (){
    }
    @Override
    public void mover(char direccion, int c) 
    {
        switch (direccion) {
            case 'U':
                this.U++;
                break;
            case 'D':
                this.D++;
                break;
            case 'R':
                this.R++;
                break;
            case 'L':
                this.L++;
                break;
            default:
                break;
        }
    }
    @Override
    public void movimientos()
    {
        int x = min(this.L,this.R); //Max movimiento posible en eje x
        int y = min(this.U,this.D); //Max movimiento posible en eje y
        //Casos base para evitar colisiones
        if (x==0) //No se mueve en eje X
        {
            if(y == 0) //Solo se movio hacia arriba o abajo
            {
                this.camino = "0"; 
                return;
            }
            else if (y > 0) //Se movio en ambas direcciones, solo puede hacer 2 movimientos
            {
                this.camino = "UD";
                return;
            }
        }
        if(y == 0) //No se mueve en eje y, solo puede ser LR o RL
        {
            this.camino = "LR";
            return;
        }
        //Resto de casos
        StringBuilder str = new StringBuilder();
        for (int i = 0; i<x ; i++) str.append("L");
        for (int i = 0; i<y ; i++) str.append("D");
        for (int i = 0; i<x ; i++) str.append("R");
        for (int i = 0; i<y ; i++) str.append("U");
        this.camino = str.toString();
    }

    @Override
    public void Imprimir() {
        if ("0".equals(this.camino))
        {
            System.out.println("0");
            System.out.println("");
        }
        else 
        {
            System.out.println(this.camino.length());
            System.out.println(this.camino);
        }
    }
    
}

class RobotAvanzado implements Robot
{
    int Double_R = 0;
    int Double_L = 0;
    int Double_U = 0;
    int Double_D = 0;
    int R = 0;
    int L = 0;
    int U = 0;
    int D = 0;
    String camino;
    public RobotAvanzado() {
    }
    @Override
    public void mover(char d, int c) {
        switch (d) {
            case 'U':
                if (c == 1) this.U += c;
                else if (c == 2) this.Double_U += c;
                break;
            case 'D':
                if (c == 1) this.D += c;
                else if (c == 2) this.Double_D += c;
                break;
            case 'R':
                if (c == 1) this.R += c;
                else if (c == 2) this.Double_R += c;
                break;
            case 'L':
                if (c == 1) this.L += c;
                else if (c == 2) this.Double_L += c;
                break;
            default:
                break;
        }
    }
    @Override
    public void Imprimir() {
        if ("0".equals(this.camino))
        {
            System.out.println("0");
            System.out.println("");
        }
        else 
        {
            System.out.println(this.camino.length()/2);
            System.out.println(this.camino);
        }
    }

    @Override
    public void movimientos() 
    {
        int y = min(this.D+this.Double_D,this.Double_U+this.U);
        int x = min(this.L+this.Double_L,this.Double_R+this.R);
        //Casos bases
        if (x==0) //No se mueve en eje X
        {
            if (this.U > 0 && this.D > 0) //Hubo al menos camino de ida y vuelta de 1 unidad, solo puede hacer 2 movimientos
            {
                this.camino = "U1D1";
                return;
            }
            else
            {
                this.camino = "0"; 
                return;
            }
            
        }
        if (y == 0) //No se mueve en eje y, solo movimiento en eje x
        {
            if (this.L > 0 && this.R > 0) //Si hay caminos de 1 es posible, sin son 2 de dos, o no llega a (0,0) o repite una posicion
            {
                this.camino = "L1R1";
                return;
            }
            else
            {
                this.camino = "0";
                return;
            }
        }
        //Resto de casos
        StringBuilder str = new StringBuilder();
        int cant_R = 0;
        int cant_L = 0;
        int cant_U = 0;
        int cant_D = 0;
        //Agregar R
        if (this.R >= x)
        {
            for (int i = 0; i<x ; i++)
            {
                cant_R ++;
                str.append("R1");
            }
        }
        else //Agregamos el maximo de R1 y completamos con R2 (nos asegura la mayor cantidad de movimientos)
        {
            int restantes = x;
            if (x % 2 == 0) //Agregar maximo R1 pares y completar con R2
            {
                while (this.R >= 2)
                {
                    str.append("R1R1");
                    restantes -= 2;
                    this.R -= 2;
                    cant_R += 2;
                }
                while(restantes > 0)
                {
                    str.append("R2");
                    restantes -=2;
                    cant_R += 2;
                }
            }
            else //Agregar Maximo R1 impares y completar con R2
            {
                while (this.R >= 1)
                {
                    str.append("R1");
                    restantes--;
                    this.R --;
                    cant_R ++;
                }
                while (restantes > 0)
                {
                    str.append("R2");
                    restantes-=2;
                    cant_R += 2;
                }
            }
        }
        //Agregar U
        if (this.U >= y)
        {
            for (int i = 0; i<y ; i++)
            {
                str.append("U1");
                cant_U ++;
            }
        }
        else //Agregamos el maximo de U1 y completamos con U2 (nos asegura la mayor cantidad de movimientos)
        {
            int restantes = y;
            if (y % 2 == 0) //Agregar maximo R1 pares y completar con R2
            {
                while (this.U >= 2)
                {
                    str.append("U1U1");
                    restantes -= 2;
                    cant_U += 2;
                    this.U -= 2;
                }
                while(restantes > 0)
                {
                    str.append("U2");
                    restantes -= 2;
                    cant_U += 2;
                }
            }
            else //Agregar Maximo U1 impares y completar con U2
            {
                while (this.U >= 1)
                {
                    str.append("U1");
                    restantes--;
                    cant_U ++;
                    this.U--;
                }
                while (restantes > 0)
                {
                    str.append("U2");
                    restantes -= 2;
                    cant_U +=2;
                }
            }
        }
        //Agregar L
        if (this.L >= x)
        {
            for (int i = 0; i<x ; i++)
            {
                cant_L ++;
                str.append("L1");
            }
        }
        else //Agregamos el maximo de L1 y completamos con L2 (nos asegura la mayor cantidad de movimientos)
        {
            int restantes = x;
            if (x % 2 == 0) //Agregar maximo R1 pares y completar con R2
            {
                while (this.L >= 2)
                {
                    str.append("L1L1");
                    restantes -= 2;
                    this.L -= 2;
                    cant_L += 2;
                }
                while(restantes > 0)
                {
                    str.append("L2");
                    restantes -= 2;
                    cant_L += 2;
                }
            }
            else //Agregar Maximo L1 impares y completar con RL
            {
                while (this.L >= 1)
                {
                    str.append("L1");
                    restantes--;
                    cant_L ++;
                    this.L--;
                }
                while (restantes > 0)
                {
                    str.append("L2");
                    restantes -= 2;
                    cant_L += 2;
                }
            }
        }
        //Agregar D
        if (this.D >= y) //Agregamos solo D1
        {
            for (int i = 0; i<y ; i++)
            {
                cant_D ++;
                str.append("D1");
            }
        }
        else //Agregamos el maximo de D1 y completamos con D2 (nos asegura la mayor cantidad de movimientos)
        {
            int restantes = y;
            if (y % 2 == 0) //Agregar maximo D1 pares y completar con D2
            {
                while (this.D >= 2)
                {
                    str.append("D1D1");
                    restantes -= 2;
                    this.D -= 2;
                    cant_D += 2;
                }
                while(restantes > 0)
                {
                    str.append("D2");
                    cant_D += 2;
                    restantes -= 2;
                }
            }
            else //Agregar Maximo D1 impares y completar con D2
            {
                while (this.D >= 1)
                {
                    str.append("D1");
                    restantes--;
                    cant_D ++;
                    this.D--;
                }
                while (restantes > 0)
                {
                    str.append("D2");
                    cant_D += 2;
                    restantes -= 2;
                }
            }
        }
        this.camino = str.toString();
        if (cant_D != cant_U || cant_R != cant_L) this.camino = "0";
    }
}