B. Deque Process

Problem Statement

We say that an array aa of size nn is bad if and only if there exists 1in41 \leq i \leq n-4 such that one of the following conditions holds:

  • ai<ai+1<ai+2<ai+3<ai+4a_i < a_{i+1} < a_{i+2} < a_{i+3} < a_{i+4}
  • ai>ai+1>ai+2>ai+3>ai+4a_i > a_{i+1} > a_{i+2} > a_{i+3} > a_{i+4}

An array is good if and only if it’s not bad. For example:

  • a=[3,1,2,4,5,6]a = [3,1,2,4,5,6] is bad because a2<a3<a4<a5<a6a_2 < a_3 < a_4 < a_5 < a_6.
  • a=[7,6,5,4,1,2,3]a = [7,6,5,4,1,2,3] is bad because a1>a2>a3>a4>a5a_1 > a_2 > a_3 > a_4 > a_5.
  • a=[7,6,5,1,2,3,4]a = [7,6,5,1,2,3,4] is good. You’re given a permutation* p1,p2,,pnp_1, p_2, \ldots, p_n.

You must perform nn turns. At each turn, you must remove either the leftmost or the rightmost remaining element in pp. Let qiq_i be the element removed at the ii-th turn.

Choose which element to remove at each turn so that the resulting array qq is good. We can show that under the given constraints, it’s always possible.

*A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t100001 \leq t \leq 10000). The description of the test cases follows.

The first line of each test case contains a single integer nn (5n1000005 \leq n \leq 100000) — the length of the array.

The second line of each test case contains nn integers p1,p2,,pnp_1, p_2, \ldots, p_n (1pin1 \leq p_i \leq n, pip_i are pairwise distinct) — elements of the permutation.

It is guaranteed that the sum of nn over all test cases doesn’t exceed 200000200000.

Output

For each test case, you must output a string ss of length nn. For every 1in1 \leq i \leq n, at the ii-th turn:

  • si=Ls_i = \mathtt{L} means that you removed the leftmost element of pp
  • si=Rs_i = \mathtt{R} means that you removed the rightmost element of pp

We can show that an answer always exists. If there are multiple solutions, print any of them.

Solution

The basic idea is to remove the minimum of the left and right elements in odd rounds, and remove the maximum of the left and right elements in even rounds.

Refer to the official solution for more details.