아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Bottle Arrangements

시간 제한2초메모리 제한2048 MB

요약
길이 n의 R/W 문자열에서 각 비평가 i마다 길이 r_i+w_i인 어떤 연속 구간에 빨간 병이 정확히 r_i개 있도록 배열을 만들거나, 불가능하면 IMPOSSIBLE을 출력한다.
난이도

보통10점 중 7점

유형
그리디, 구현, 수학
정답자
아직 제출이 없습니다

문제

Gabriella has been instructed to organize a renowned wine tasting event which will be attended by mm critics. On display, there will be nn different varieties of wine, each of which can either be a red wine or a white wine.

The wines will come in nn bottles arranged in a line on the table, and, for convenience, each critic will sip from a contiguous interval of bottles: that is, he/she will taste exactly the bottles at position aa, a+1a + 1, …\dots, bb for some 1≤a≤b≤n1 ≤ a ≤ b ≤ n. The interval depends on the critic, who will select it on the spot according to their preferences. In fact, the ii-th critic (1≤i≤m1 ≤ i ≤ m) has requested that he/she wants to taste exactly r_ir\_i red wines and w_iw\_i white wines.

Gabriella has yet to choose how many bottles of red wine and white wine there will be, and in what order they will appear. Help her find an arrangement (that is, a sequence of nn bottles of either red or white wine) that satisfies the requests of all the critics, or state that no such arrangement exists.

입력

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤1001 ≤ t ≤ 100) — the number of test cases. The descriptions of the tt test cases follow.

The first line of each test case contains two integers nn and mm (1≤n≤1001 ≤ n ≤ 100, 1≤m≤1001 ≤ m ≤ 100) — the number of bottles of wine and the number of critics.

Each of the next mm lines contains two integers r_ir\_i and w_iw\_i (0≤r_i,w_i≤1000 ≤ r\_i , w\_i ≤ 100, r_i+w_i≥1r\_i + w\_i ≥ 1) — the number of red and white wines that the ii-th critic wants to taste.

출력

For each test case, if at least one solution exists, print a string of length nn made up of the characters R and W, where the jj-th character (1≤j≤n1 ≤ j ≤ n) denotes the type of the wine in the jj-th bottle of the arrangement (R for red and W for white).

If there are multiple solutions, print any. If no solution exists, print the string IMPOSSIBLE.

예제1

  1. 예제 1

    입력
    3
    5 3
    1 0
    3 2
    2 2
    4 3
    2 1
    1 1
    0 3
    3 2
    0 2
    0 3
    
    예상 출력
    RWRRW
    IMPOSSIBLE
    WWW