Under construction

Still being built. Things may change

Ferries (Hard)

Time limit10sMemory limit1024 MB

Summary
Given car positions a_1 to a_k seen during a trip on 2n cars, find the fewest ferry crossings and an L/R string of ferry types that produces them.
Level

Hard8 of 10

Topics
Math, Bit manipulation
Solved
No attempts yet

Problem

One day a group of friends jumped into their 2n2n cars and went on a road trip into the lake district. The cars were numbered 1 through 2n2n. At the start they were driving in this order.

During the trip the convoy met several ferries, one after another. Each ferry was exactly large enough to hold all 2n2n cars, and no other cars were around at any time. Every time the cars used a ferry, their order got mixed up. The loading and unloading process causes this.

A ferry is a long, narrow boat with room for two columns of cars, each with nn cars. When loading, the first nn cars form the first column and the last nn cars form the second column. When unloading, all cars drive away at the same time, and they must zip together into a single convoy. The first car in the new order is the first car from the right column. The second car is the first car from the left column. The third car is the second car from the right column, and so on, alternating between right and left.

Above: Cars 1 through 6, in this order, just boarded a type-R ferry (from the bottom of the figure). The cars will leave this ferry in the following order: 1, 4, 2, 5, 3, 6.

There are two types of ferries. On type-L ferries the crew instructs the cars to fill the Left column first. On type-R ferries the cars fill the Right column first. The ferry type does not affect how the cars leave. The first car to leave is always the first car in the right column.

The trip is now over. Your car was car xx, so at the beginning it was the xx-th car. You remember a sequence a1,…,aka_1, \ldots, a_k of positive integers. The number aia_i means that at some point your car was the aia_i-th car from the beginning of the convoy. The numbers are in chronological order: your car was in position aia_i before it was in position ai+1a_i + 1, for all ii.

Compute the smallest possible number ff of ferries you encountered during the trip. Produce a proof as well: one possible sequence of exactly ff Ls and Rs, such that the ff ferries could have been type-L and type-R ferries in the given order.

Input

The first line of the input file contains an integer t=100t = 100, the number of test cases. Each test case is preceded by a blank line.

Each test case consists of two lines. The first line contains the integers nn, xx, and kk, where 1≤x≤2n1 \le x \le 2n. The second line contains the integers a1,…,aka_1, \ldots, a_k.

Output

For each test case, output a single line with the number ff, a colon, and one possible shortest string of Ls and Rs. There are no spaces in the output.

Constraints

1≤n≤10181 \le n \le 10^{18}

1≤k≤1041 \le k \le 10^4

Hints

In the first example there were no ferries, so the car stayed in the first place.

In the second example the first type-L ferry moves the car to position 2, and the second type-L ferry moves it to position 4.

In the third example, RR moves the car from 2 to 5, L moves it from 5 to 3, RRL moves it from 3 to 1, and L moves it from 1 to 2.

Examples1

  1. Example 1

    Input
    3
    
    10 1 3
    1 1 1
    
    10 1 2
    2 4
    
    3 2 4
    5 3 1 2
    
    Expected output
    0:
    2:LL
    7:RRLRRLL