QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#3076. Game 2048

Statistics

Some computer games are extremely fun and this problem may be about one of these.

You are given a sequence of one dimensional blocks, each of length that is a power of two. The goal of the game is to merge all the blocks into one big block. The blocks are presented one by one, and for each one you have to decide whether to stick it immediately to the left or immediately to the right of the previous blocks.

Every time two blocks of the same size are adjacent, they merge into one block that is twice as long as each of them. Note that, as long as possible, the resulting blocks immediately merge with adjacent ones. For example, if the current sequence of blocks is $2, 4, 16$, then sticking $2$ on the left side leads to $8, 16$, while sticking it on the right side gives $2, 4, 16, 2$. Note that at any moment there is at most one mergeable pair of blocks.

You have lost the game (again!) and you are wondering whether there was any way to win at all. Analyze the sequence to find out.

Input

The first line of input contains the number of test cases $T$. The descriptions of the test cases follow:

Each test case consists of two lines. The first one contains a positive integer $n \le 1\,000$ — the length of the sequence. The next line contains a sequence of $n$ block lengths, each a power of two. The sum of all the lengths does not exceed $2^{13}$.

The size of the input file does not exceed 0.4 MiB.

Output

For each test case, output one line containing the word “no” if winning the game is not possible. Otherwise, output a word consisting of $n$ letters ‘l’ and ‘r’, denoting whether the corresponding block should be stuck to the left or to the right. Note that for the first block it does not matter.

Examples

Input 1

3
9
2 8 4 1 1 4 4 4 4
5
2 16 4 8 2
3
2 2 2

Output 1

rrrlllrrr
no
no

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.