TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

You have a weighing scale and N weights. Initially both sides of the scale are empty and you have all the N weights in hand. You start by taking a weight randomly and putting it on one side of the scale. You repeat the following procedure until all the weights go to one of the sides of the scale. After each step, you write 'L' if the left side of the scale is heavier and 'R' otherwise. Note that we write R even if the weights of both sides of the scale are equal.


After the procedure, you will have written a string of length N containing 'L' and 'R'. Now, given this output string and value of each of the weight, can you reconstruct the moves made to achieve this particular string?
Warn: 本題有 specialjudge

Input Format

First line of the input file contains number of test cases, T. This is followed by the description of T test cases. Each test case description starts with integer N, number of weights. Then next line contains N weights w0, w1, wn separated by single space. Next line contains a string of length N, consisting of only 'L' and 'R', which is the output string of the process.


-> number of test cases, T <= 25.

-> number of weights, 1 <= N <= 10000.

-> All weights are positive and less than 1,000,000,000.

-> No two weights are of equal value.

Output Format

For each test case you will have to output N moves, one per line. For each move print the 0 based index of the weight and the side of the scale you will put this weight in. Output of different test cases is separated by a blank line. There is no blank line after the output of final test case. Please check the sample output for details.


Note
If there are multiple move sequences possible for the given output string, you can output any one of them.

Sample Input 1

2
2
1 3
LR
2
2 1
LL

Sample Output 1

0 Left
1 Right

0 Left
1 Left

Hints

Problem Source

Migrated from old NTUJ.

CodeCraft 2010

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 20000